import com.sun.source.tree.Tree;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//Map 接口的哈希表和链接列表实现
Map<String, Integer> map = new TreeMap<>();
while (true){
String str = sc.next();
if (str.equals("end")){
break;
}
if (map.containsKey(str)){
map.put(str, map.get(str)+1);
}
else {
map.put(str, 1);
}
}
//TreeMap 默认排序规则:按照key的字典顺序来排序(升序)
//key有序
for (String i: map.keySet()){
System.out.println(i + " " + map.get(i));
}
}
}
sdut-Collection(Map)-1 读中国载人航天史,汇航天员数量,向航天员致敬
最新推荐文章于 2024-07-19 17:37:28 发布