将文本文件转换为Java Set< String>使用Commons或Guava [英] Text file into Java Set<String> using Commons or Guava
本文介绍了将文本文件转换为Java Set< String>使用Commons或Guava的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将文件中的每一行加载到HashSet集合中.有没有简单的方法可以做到这一点?
I would like to load each line in a file into HashSet collection. Is there a simple way to do this?
推荐答案
怎么样:
Sets.newHashSet(Files.readLines(file, charSet));
(使用番石榴).
参考:
- Files.readLines()
- Sets.newHashSet()
这篇关于将文本文件转换为Java Set< String>使用Commons或Guava的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文