简要概括就是统计若干字符串中,出现最多次数的字符串。
class Main {
Scanner scan = new Scanner(System.in);
ArrayList<String> list = new ArrayList<String>();
while(scan.hasNext()){
list.add(scan.nextLine());
}
Map<String,Integer> map = new HashMap<>();
for(int i = 0;i<list.size();i++){
String key = list.get(i);
if(!map.containsKey(key)){
map.put(key,1);
} else {
map.put(key,map.get(key) + 1);
}
int max = 1;
for(Integer value : map.values()){
if(value >= max){
max = value;
}
}
for(Map.Entry<String,Integer> entry : map.entrySet()){
if(max == entry.getValue()) {
System.out.println(entry.getKey());
}
}
}