Finding Duplicates in Array and printing them only Once

前端 未结 6 1236

I am trying to loop through my array and find all the numbers that are repeating more than once:

E.G: if there is 1 1 2 3 4

It should print saying \

6条回答
  •  甜味超标
    2021-01-21 23:50

    Integer[] ints = {1, 1, 2, 3, 4};
    
    System.out.println(new HashSet(Arrays.asList(ints)));
    

    Output: [1, 2, 3, 4]

提交回复
热议问题