判断一个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");
}
}
}

}
posted @ 2015-10-13 11:43  爱吃西红柿  阅读(4135)  评论(0编辑  收藏  举报