CountedSet<E>
Posted by Bruce Tsai
說明
可計算次數的 Set 集合。
範例
CountedSet<String> countedSet = new CountedSet<>();
countedSet.add("Bruce");
countedSet.add("Bruce");
countedSet.add("Linda");
countedSet.add("James");
countedSet.add("Linda");
countedSet.add("Robert");
countedSet.add("Yilin");
countedSet.add("Bruce");
for (String name : countedSet) {
System.out.printf(
"%s appears %d times%n",
name,
countedSet.count(name));
}
輸出結果
Yilin appears 1 times
Robert appears 1 times
Bruce appears 3 times
Linda appears 2 times
James appears 1 times