Skip to content
Advertisement

Does .asSet(…) exist in any API?

I’m looking for a very simple way to create a Set.

Arrays.asList("a", "b" ...) creates a List<String>

Is there anything similar for Set ?

Advertisement

Answer

Now with Java 8 you can do this without need of third-party framework:

Set<String> set = Stream.of("a","b","c").collect(Collectors.toSet());

See Collectors.

Enjoy!

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement