Java 获取重复的值 并统计总数
public static void main(String[] args) {
List
l.add("a") ;
l.add("a") ;
l.add("b") ;
l.add("b") ;
l.add("b") ;
l.add("c") ;
l.add("d") ;
l.add("d") ;
l.add("e") ;
l.add("e") ;
l.add("e") ;
l.add("e") ;
l.add("e") ;
l.add("e") ;
System.out.println(l);
Map<String, Integer> map = new HashMap<String, Integer>();
for(String item: l){
if(map.containsKey(item)){
map.put(item, map.get(item).intValue() + 1);
}else{
map.put(item, new Integer(1));
}
}
Iterator
while(keys.hasNext()){
String key = keys.next();
System.out.print(key + ":" + map.get(key).intValue() + ", ");
}
}

浙公网安备 33010602011771号