import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class ArrayToHashSet {
public static void main(String[] args) {
String[] arr = { "one", "two", "third" };
Set<String> hs = new HashSet<String>(Arrays.asList(arr));
// print hashset
System.out.println("hashset is =" + hs);
}
}
Output:
hashset is =[two, one, third]
import java.util.HashSet;
import java.util.Set;
public class ArrayToHashSet {
public static void main(String[] args) {
String[] arr = { "one", "two", "third" };
Set<String> hs = new HashSet<String>(Arrays.asList(arr));
// print hashset
System.out.println("hashset is =" + hs);
}
}
Output:
hashset is =[two, one, third]
This line seems to incorrect(asLIST):
ReplyDeleteSet hs = new HashSet(Arrays.asList(arr));