Search code examples
javatext-filesguavahashset

Text file into Java Set<String> using Commons or Guava


I would like to load each line in a file into HashSet collection. Is there a simple way to do this?


Solution

  • How about:

    Sets.newHashSet(Files.readLines(file, charSet));
    

    (using Guava).

    References: