public class SetTest {
public static void main(String[] args) throws IOException {
Set<String> hashset=new HashSet<>();
long totalTime=0;
//int count=0;
Scanner in=new Scanner(Paths.get("c:\\Users\\xiao\\Desktop\\test.txt"));
//Scanner in=new Scanner(System.in);
while(in.hasNext()){
String word=in.next();
System.out.println(word);
long callTime=System.currentTimeMillis();
hashset.add(word);
callTime=System.currentTimeMillis()-callTime;
totalTime+=callTime;
}
System.out.println(hashset.size());
Iterator<String> iterator =hashset.iterator();
for(int i=1;i<=20&&iterator.hasNext();i++){
System.out.println(iterator.next());
}
System.out.println("...");
System.out.println(hashset.size()+" distinct words."+totalTime+" milliseconds");
}
}
第一个循环一直跳不出来,控制台也没有结束,为什么呢,谢谢各位大哥