package main.java.test;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;
/**
* @className: main.java.test.Test002
* @description: TODO
* @author: ljx
* @create: 2022-08-26 16:43
*/
public class Test002 {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
Map<String,Integer>map =new LinkedHashMap<>();
while(in.hasNextLine()){
String str = in.nextLine();
int index=str.lastIndexOf("\\");
str=str.substring(index+1,str.length());
if(map.containsKey(str)){
map.put(str,map.get(str)+1);
}else{
map.put(str,1);
}
}
map.entrySet().stream().sorted((o1,o2)->o2.getValue()-o1.getValue()).limit(8).forEach(e->{
int index=e.getKey().lastIndexOf(" ");
if(index>16){
System.out.println(e.getKey().subSequence(index-16,e.getKey().length())+" "+e.getValue());
}else{
System.out.println(e.getKey()+" "+e.getValue());
}
});
}
}
根据entry的value对Map进行排序
最新推荐文章于 2024-09-01 11:33:01 发布