Sunday, 7 February 2016

Remove duplicates from an Array

Remove duplicates from an Array:
==========================
package tesngdemos;

import java.util.HashSet;

public class ArrayDemo {

    public static void main(String[] args) {
       
        int[] a = {10,10,20,20,30,30,90,90};
        HashSet hashSet = new HashSet();
        for (int i = 0; i < a.length; i++) {
            hashSet.add(a[i]);
        }
        System.out.println(hashSet);
    }
   
}

No comments:

Post a Comment