import java.util.HashMap; import java.util.Map; public class EntrySets { public static void main(String[] args) { Map<Object, Object> map = new HashMap<Object, Object>(); map.put("k1", "v1"); map.put("k2", "v2"); getItem(map); } static void getItem(Map map) { map.forEach((key, value) -> print(key + ":" + value)); } static void iterByKey(Map map) { /** iter map by key */ for (Object k : map.keySet()) { String v = map.get(k).toString(); } } static void print(Object o) { System.out.println(o); } }
原文地址:https://www.cnblogs.com/SunshineKimi/p/12233373.html
时间: 2024-11-06 16:40:53