java操作map集合
import java.util.HashMap; import java.util.Map; public class MapExample { public static void main(String[] args) { // 创建一个HashMap对象 Map<String, Integer> map = new HashMap<>(); // 添加键值对 map.put("apple", 1); map.put("banana", 2); map.put("orange", 3); // 查找键 Integer key = 2; Integer value = map.get(key); System.out.println(key + " : " + value); // 删除键值对 map.remove("banana"); // 遍历集合 for (Map.Entry<String, Integer> entry : map.entrySet()) { System.out.println(entry.getKey() + " : " + entry.getValue()); } } }
#########################
标签:map,java,HashMap,Map,put,key,集合 From: https://www.cnblogs.com/herd/p/17363147.html