其他分享
首页 > 其他分享> > Map操作

Map操作

作者:互联网

Map遍历

Map<Integer, String> map = new HashMap<>();
for (Map.Entry<Integer, String> entry : map.entrySet()) {
    System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}

Map<Integer, String> map = new HashMap<>();
//遍历map中的键
for (Integer key : map.keySet()) {
    System.out.println("Key = " + key);
}
//遍历map中的值
for (String value : map.values()) {
    System.out.println("Value = " + value);
}

Map<Integer, String> map = new HashMap<>();
Iterator<Map.Entry<Integer, String>> entries = map.entrySet().iterator();
while (entries.hasNext()) {
    Map.Entry<Integer, String> entry = entries.next();
    System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}

Map排序

标签:Map,遍历,map,System,entries,entry,操作
来源: https://blog.csdn.net/ycjiang00/article/details/120445253