Search code examples
javacollections

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 ?


Solution

  • 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!