/** * @author lautturi.com * Java example: how to remove duplicates in an array */ import java.util.*; public class Lautturi { public static void main(String[] args) { int[] numArray = { 11,4,12,7,55,8,12,8,13,55,12,7 }; Set<Integer> set = new HashSet<>(); for (Integer num : numArray) { if (set.add(num) == false) { // duplicate element } } Integer[] arr = set.toArray(new Integer[set.size()]); // print the new array without duplicate elements for (Integer i : arr) { System.out.print(i+" "); } } }Source.www:lautturi.com
output:
4 7 55 8 11 12 13