-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetTest.java
More file actions
27 lines (25 loc) · 732 Bytes
/
SetTest.java
File metadata and controls
27 lines (25 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.util.Set;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Iterator;
public class SetTest{
public static void main(String[] args){
Set<String> words = new HashSet<String>();
long totalTime = 0;
try(Scanner in = new Scanner(System.in)){
while(in.hasNext()){
String word = in.next();
long callTime = System.currentTimeMillis();
words.add(word);
callTime = System.currentTimeMillis() - callTime;
totalTime += callTime;
}
}
Iterator<String> iter = words.iterator();
for(int i = 0; i < 10 && iter.hasNext(); i++){
System.out.println(iter.next());
}
System.out.println(words);
System.out.println("words number:"+words.size()+"total time:"+totalTime);
}
}