Частота каждого элемента из списка на Java
public static void main(String[] args)
{
List<String> list = Arrays.asList("B", "A", "A", "C", "B", "A");
Set<String> distinct = new HashSet<>(list);
for (String s: distinct) {
System.out.println(s + ": " + Collections.frequency(list, s));
}
}
}
Filthy Fox