我想将文件中的每一行加载到 HashSet 集合中。有没有一种简单的方法可以做到这一点?
怎么样:
Sets.newHashSet(Files.readLines(file, charSet));
(使用番石榴)。
参考:
- 文件.readLines() http://guava-libraries.googlecode.com/svn/trunk/javadoc/com/google/common/io/Files.html#readLines%28java.io.File,%20java.nio.charset.Charset%29
- Sets.newHashSet() http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/Sets.html#newHashSet(java.lang.Iterable)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)