判断一个key 是否在map中存在

public class Test {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
HashMap map = new HashMap();
map.put("key1", "value1");
map.put("key2", "value2");
map.put("key3", "value3");
Iterator keys = map.keySet().iterator();
while(keys.hasNext()){
String key = (String)keys.next();
if("key2".equals(key)){
System.out.println("这里面有key2");
}
}
}

}
原文地址:https://www.cnblogs.com/sily-boy/p/4874127.html