我有一个字符串到整数的映射。我想检查地图是否有某个字符串,如果有,请修改它映射到的整数值。
Map <String, Integer> m= new SortedMap <String,Integer>();
Map <String, Integer> m2 = new SortedMap<StringInteger>();
//do some stuff
Iterator <String,Integer> i = m2.iterator();
//add some values into the first map first map
while (i.hasNext()){
String temp = i.next();
int found = m.get(temp);
if ( found != null) {//this is giving me a syntax error , something about how ints
can't be null , do I just compare it to zero
//process value that temp maps to
averages.put(temp, val); //
}
}
另外,当我在第二个循环中输入密钥时,它会删除第一个密钥,并用新的过程值放入另一个密钥。