Printing certain values using Collections.frequency()
问题 I have an array as follows: int[] array = {11, 14, 17, 11, 48, 33, 29, 11, 17, 22, 11, 48, 18}; What I wanted to do was to find the duplicate values, and print them. So my way of doing this was to convert to ArrayList , then to Set and use a stream on the Set . ArrayList<Integer> list = new ArrayList<>(array.length); for (int i = 0; i < array.length; i++) { list.add(array[i]); } Set<Integer> dup = new HashSet<>(list); I then used a stream to loop through it and print the values using