*/Map <String,String>map =newHashMap<String,String>(); map.put("熊大","棕色"); map.put("熊二","黄色");for(Map.Entry<String, String> entry : map.entrySet()){StringmapKey=entry.getKey();StringmapValue=entry.getValue(); System.out.println(mapKey+":"+mapValue); } 方法二:在for...
一、list 转 map List<Student> list= new ArrayList<>(); 1、第一种,List<Student> 转化Map<String,String> Map<String,String> map = list.stream() .collect(Collectors.toMap( Student::getName, Student::getAge, (k1, k2) -> k2)); 1、第一种,List<Student> 转化Map<String,Student> Map<Str...
Map<String, Integer> map = names.stream().collect(Collectors.toMap(v -> v, v -> 1)); System.out.println(map); } } 1. 2. 3. 4. 5. 6. 7. 程序运行输出 {Answer=1, AnswerAIL=1, AI=1} 1. 将List 转为 Map<K, V> public static void main(String[] args) thr...
Map<String, String> map = new HashMap<>(); map.put("xiao", "zhang"); // map转字符串 String a = JSON.toJSONString(map); // 字符串转map map = JSON.parseObject(a,Map.class); 1. 2. 3. 4. 5. 6. 5.一个list转另一个list 两个不同对象的列表,但是有相同字段。 // 通过stream(...
publicstaticvoidmain(String[]args){List<Student>stu=newArrayList<>();Students1=newStudent();s1.setId(1);s1.setName("zs");Students2=newStudent();s2.setId(1);s2.setName("ls");Students3=newStudent();s3.setId(3);s3.setName("ww");stu.add(s1);stu.add(s2);stu.add(s3);stu.stre...
Map<String,List<String>> materielSeqMap = opList.stream() .collect(Collectors.groupingBy(DeviceDto::getDeviceCode,Collectors.mapping(DeviceDto::getDeviceName,Collectors.toList())); 转换为map,然后值根据排序获取最大的一个 tableMap = list.stream().filter(t->t.getTargetSchemaName().equals(e.ge...
Map<String, Map<String, List<String>>> testMap = foos.stream().collect(Collectors.groupingBy(e -> e.getAreaName(), Collectors.groupingBy(e -> e.getObjectName(), Collectors.collectingAndThen(Collectors.toList(), e -> e.stream().map(f -> f.getLineName())); The ...
{code=01, name=yuwen}, {code=02, name=shuxu}, {code=03, name=yingyu}] //期望转为 Map<String, String> map = new HashMap<>(); map.put("yuwen","01"); map.put("shuxu","02"); map.put("yingyu","03"); System.out.println(map.toString()); //{yingyu=03, yuwen=01, shu...
Map<String, Map<Integer, String>> collect = materialResourceRelEntities .stream() .collect(Collectors.groupingBy(ElectronicMaterialResourceRelEntity::getChapterName, Collectors.toMap(ElectronicMaterialResourceRelEntity::getSort, ElectronicMaterialResourceRelEntity::chapterImageId))); ...