java中的map

Map 初始化

Map<String, String> map = new HashMap<String, String>();

插入元素

map.put("key1", "value1");

获取元素

map.get("key1")

移除元素

map.remove("key1");

清空map

map.clear();

使用for循环    keySet()遍历

for (String key : map.keySet()) {
    System.out.println(key + "" + map.get(key));
}

参考自:https://www.jianshu.com/p/27577315af0c

原文地址:https://www.cnblogs.com/150536FBB/p/12024113.html