【发布时间】:2019-09-23 05:28:27
【问题描述】:
我有一个包含字符串键和整数值的映射,我试图将这些值与阈值(例如 40)进行比较,并将所有值大于阈值的键打印到一组中。这是我的代码和我得到的错误。我是java新手
int m = 40;
Set<Map.Entry<String, Integer>> set = map.entrySet();
System.out.println();
Iterator<Map.Entry<String, Integer>> i = set.iterator();
while (i.hasNext() ) {
Map.Entry e = i.next();
if(e.getValue() > m) {
set.add(e.getKey());
}
System.out.println("Set of local file names and malware score : "+ i.next());
}
错误:
no suitable method found for add(Object) set.add(e.getKey()); ^ method Collection.add(Entry<String,Integer>) is not applicable (argument mismatch; Object cannot be converted to Entry<String,Integer>) method Set.add(Entry<String,Integer>) is not applicable (argument mismatch; Object cannot be converted to Entry<String,Integer>) 2 errors
【问题讨论】:
标签: java