public static void main(String[] args) { // 1.数据准备 List<Map<String,Object>> list = new ArrayList<>(); Map<String,Object> map = new HashMap<>(); map.put("name", "songwp"); map.put("age", 25); map.put("gender", "male"); Map<String,Object> map1 = new HashMap<>(); map1.put("name", "zhangsan"); map1.put("age", 26); map1.put("gender", "men"); Map<String,Object> map2 = new HashMap<>(); map2.put("name", "lisi"); map2.put("age", 24); map2.put("gender", "male"); list.add(map); list.add(map1); list.add(map2); System.out.println("原始数据:"+list); // 2.根据name转成Map Map<Object, Map<String, Object>> resultMap = list.stream().collect(Collectors.toMap(m -> m.get("name"), m -> m)); System.out.println("根据name转成Map的结果:"+resultMap); // 3.根据name转成List List<Object> names = list.stream().map(m -> m.get("name")).collect(Collectors.toList()); System.out.println("根据name转成List的结果;"+names); }
标签:Map,name,map,List,list,获取,put,属性 From: https://www.cnblogs.com/songweipeng/p/18510141