如何让树状按字母顺序排序? 并删除重复..它已经让我坚持了一天。也许我需要得到一些睡眠..Treeset按字母顺序排序
public static void main(String[] args) {
String fileName = args[0];
String words;
Scanner s = null;
Iterator itr;
try {
s = new Scanner(new BufferedReader(new FileReader(fileName)));
while (s.hasNext()) {
words = s.next();
TreeSet<String> ts = new TreeSet<String>();
ts.add(words);
System.out.println(ts);
}
} catch (FileNotFoundException fnfe) {
System.exit(0);
} finally {
if (s != null) {
s.close();
}
}
}
你有重复的东西吗?在一个集合? – 2013-03-19 19:59:18
你正在为每个单词制作一个新的TreeSet ... – n00begon 2013-03-19 19:59:51
@KatjaChristiansen好吧,它*是*可能的 - 设计得很糟糕的'hashCode()'或'equals()' - 但我想它更加棘手'String' class :) – 2013-03-19 20:02:06