List<String> aa = ....;
Map<String, Integer> map = new HashMap<String,Integer>();
for (int i=0;i<aa.size();i++) {
String temp = aa .get(i);
if(map.containsKey(temp))
map.put(temp, map.get(temp)+1);
else
map.put(temp, 1);
}
List<Integer> sortList = new ArrayList<Integer>();
//由于存在重复次数相同的元素,所以将mapSort设置为Map<Integer,List<String>>,其中List<String>用来存储次数相同的String
Map<Integer,List<String>> mapSort = new HashMap<Integer,List<String>>();
for(Map.Entry<String, Integer> entry: map.entrySet()){
String mapKey = entry.getKey();
Integer mapValue = entry.getValue();
if(mapSort.containsKey(mapValue)){
对Iterable<String>中的数据进行用重复度进行计数,然后提取重复数最多的前3个
最新推荐文章于 2024-10-20 08:45:00 发布