标签:second while michael alt ges for 核心 exce pac
java 基础数据结构 SET, java核心编程
统计不同的字符串
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;
public class SetTest {
public static void main(String[] args) {
Set<String> words = new HashSet<>();
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 = 1; i <= 20 && iter.hasNext(); i++) {
System.out.println(iter.next());
}
System.out.println("...");
System.out.println(words.size() + " distinct words. " + totaltime +
" milliseconds.");
}
}
java SetTest < alice.txt
> /opt/jdk-14.0.2+12/bin/java -XX:+ShowCodeDetailsInExceptionMessages -Dfile.encoding=UTF-8 -cp /home/ling/.vscode-server/data/User/workspaceStorage/f8f4922c995979dd665d7ceea52d62e1/redhat.java/jdt_ws/java_c7cf4489/bin SetTest < alice.txt
frowning
prepare
half
don‘t
spoke
mine,
hall
_should_
turtles,
mine.
pretend
gimble
tea
twinkling
would
pick
rabbit
Michael
character,
electronically
...
4654 distinct words. 4 milliseconds.
标签:second while michael alt ges for 核心 exce pac
原文地址:https://www.cnblogs.com/eat-too-much/p/13824977.html