.
int[] arr = {1, 6, 2, 8, 5, 4, 7, 7, 5, 7};
Map<Integer, Long> counts = Arrays.stream(arr)
.boxed()
.collect(collectingAndThen(groupingBy(n -> n, counting()),
map -> map.entrySet().stream()
.filter(n -> n.getValue() > 1)
.collect(toMap(Entry::getKey, Entry::getValue))
));
System.out.println(counts.toString());
int[] arr = {1, 6, 2, 8, 5, 4, 7, 7, 5, 7};
Map<Object, Long> counts = Arrays.stream(arr)
.collect(ArrayList::new, ArrayList::add, ArrayList::addAll)
.stream()
.collect(groupingBy(Function.identity(), counting()));
counts.values().removeIf(count -> count < 2);
System.out.println(counts.toString());