一句话总结:.keySet()方法获取map中所有的key(键)
代码如下:
public static void main(String[] args) {
Map<String,String> map1 = new HashMap<String, String>();
map1.put("键1","值JAVA");
map1.put("键2","值PHP");
map1.put("键3","值Python");
map1.put("键4","值C#");
map1.put("键5","值Html");
System.out.println("-----执行键map.keySet(),结果打印如下-----");
System.out.println(map1.keySet());
System.out.println("-----迭代map获取map中所有的key及其对应的值-----");
for(String map2 : map1.keySet()){
String s = map1.get(map2).toString();
System.out.println(map2+"+++"+s);
}
}
}
运行结果如下: