To initialize a
Set
in Java, do this: new HashSet(Arrays.asList(values))
.HashSet
takes a Collection
as an argument, so if you want to initialize your Set
in a single line, then use Arrays.asList
to supply your values.
Set<String> set = new HashSet<>(Arrays.asList("one", "two", "three"));
System.out.println(set); // [one, two, three]