array to set in java code example
Example 1: array to set java
Integer[] sourceArray = { 0, 1, 2, 3, 4, 5 };
Set<Integer> targetSet = new HashSet<Integer>(Arrays.asList(sourceArray));
Example 2: java convert a set to array
Set<String> set = new HashSet<String>();
set.add("Apple");
set.add("Orange");
set.add("Banana");
String[] myArray = new String[set.size()];
set.toArray(myArray);