Posted in: Core Java,Java.Util,Java.Util.SimpleDateFormat,Set
First Covert arrays to java.util.List using Arras.asList( ) Method. then pass the list object as parameter while creating a Set.
import java.util.*;
public class ConvertArrayToSet {
public static void main(String[] args) {
Integer[] numbers = {7, 7, 8, 9, 10, 8, 8, 9, 6, 5, 4};
List list = Arrays.asList(numbers);
Set set = new HashSet(list);
for (Iterator iterator = set.iterator(); iterator.hasNext();) {
Object o = iterator.next();
System.out.print(o + ", ");
}
}
}