Map Map初始化 Map<String, String> map = new HashMap<String, String>(); 添加數據 map.put("key1", "value1"); 刪除數據 map.remove("key1"); 獲取數據 map.get("key1"); 清空m ...
Map
Map初始化
Map<String, String> map =
new
HashMap<String, String>();
添加數據
map.put(
"key1"
,
"value1"
);
刪除數據
map.remove(
"key1"
);
獲取數據
map.get(
"key1"
);
清空map
map.clear();
使用keySet()遍歷
for
(String key : map.keySet()) {
System.out.println(key +
" :"
+ map.get(key));
}
使用entrySet()遍歷
for
(Map.Entry<String, String> entry : map.entrySet()) {
System.out.println(entry.getKey() +
" :"
+ entry.getValue());
}