Remove duplicates in arrays of java
Remove duplicates from an array using hashset {1, 2, 2, 3, 4, 4, 5} import java.util.*; class ASC { public static void main(String args[]) { int arr[]={1, 2, 2, 3, 4, 4, 5}; HashSet<Integer> s=new HashSet<>(); for(int a:arr)//a=5 { s.add(a);//s=1 2 3 4 5 } System.out.println(s); } }