java Map 迭代key,value 最简洁的方法
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); } }