Remove duplicates from integer array

To Preserve the ordering and to remove duplicates in the integer array, you can try this:

public void removeDupInIntArray(int[] ints){
    Set<Integer> setString = new LinkedHashSet<Integer>();
    for(int i=0;i<ints.length;i++){
        setString.add(ints[i]);
    }
    System.out.println(setString);
}

Hope this helps.

Leave a Comment