一、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...
list.add(newStudent("1003", "小D"));//将list转map 【key为1个属性,value为1个属性】Map<String, String> map =list.stream().collect(Collectors.toMap( Student::getNo, Student::getName, (key1 , key2)-> key1//(map的键重复不会报错,下面已经处理)));//将list转map 【key为多个属性,valu...
List<Map<String,String>> listObjectFir = (List<Map<String,String>>) JSONArray.parse(strArr); System.out.println("利用JSONArray中的parse方法来解析json数组字符串"); for(Map<String,String> mapList : listObjectFir){ for (Map.Entry entry : mapList.entrySet()){ System.out.println( entry.ge...
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...
要实现List<Map>转换为List<String>,我们可以遍历List<Map>中的每个Map对象,然后将Map对象中的值转换为字符串并添加到List<String>中。下面是一个示例代码: importjava.util.ArrayList;importjava.util.List;importjava.util.Map;publicclassMapToStringConverter{publicstaticList<String>convertListMapToListString(List...
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.getKey()))...
{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...
@Testpublicvoidtest02(){List<String>names=Arrays.asList("tom","jack","jerry","tom");Map<String,Integer>collect=names.stream().collect(toMap(Function.identity(),String::length));System.out.println(collect)}/* 因为List包含两个tom,转成Map会有两个同样的Key,这个是不允许的。所以会报错: ...
package com.zkn.newlearn.json; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import java.util.List; import java.util.Map; public cl…