Java get the frequency of each element in the list

www.l‮ua‬tturi.com
Java get the frequency of each element in the list
/**
 * @author lautturi.com
 * Java example:Counts the number of occurrences of an element in the list
 */

import java.util.*;

public class Lautturi {

	public static void main(String[] args) {

		List<String> list = Arrays.asList("hello","lautturi","java","python","java","lautturi","world");
		
        Set<String> distinct = new HashSet<>(list);
        for (String s: distinct) {
            System.out.println(s + ": " + Collections.frequency(list, s));
        }
		
	}
}

output

python: 1
java: 2
world: 1
lautturi: 2
hello: 1
Created Time:2017-09-06 10:59:03  Author:lautturi