you can take the help of Set collection
int end = arr.length;
Set
for(int i = 0; i < end; i++){ set.add(arr[i]); } now if you will iterate through this set, it will contain only unique values. Iterating code is like this : Iterator it = set.iterator(); while(it.hasNext()) { System.out.println(it.next()); } If you are allowed to use Java 8 streams: Arrays.stream(arr).distinct().toArray();