第一种:
boolean flag=map.containsKey("opt")
第二种:
HashMap map = new HashMap();
map.put("1", "value1");
map.put("2", "value2");
Iterator keys = map.keySet().iterator();
while (keys.hasNext()) {
String key = (String) keys.next();
if ("2".equals(key)) {
System.out.println("存在key");
}
}