其他分享
首页 > 其他分享> > map转listmap

map转listmap

作者:互联网

package com;

import java.util.*;
import java.util.stream.Collectors;


public class LambadaTest {

public static void main(String[] args) {
/* Map<String,List<Map>> map = new HashMap<>();
// List<Map<String,String >> strings = new ArrayList<>();

for (int i = 0; i < 6; i++) {
if (i<4) {
List<Map> list = map.get("1");
if (list==null) {
list = new ArrayList<>();
}
HashMap<String ,String> map1 = new HashMap<>();
map1.put("busicodes",i+"");
list.add(map1);
map.put("1",list);
}else {
List<Map> list = map.get("2");
if (list==null) {
list = new ArrayList<>();
}
HashMap<String ,String> map1 = new HashMap<>();
map1.put("busicodes",i+"");
list.add(map1);
map.put("2",list);
}
}

System.out.println(map);*/

b();


}

public static void a(){

/*Map<String,List<Map>> map = new HashMap<>();

List<Map> maps = map.get(taskType);
if (maps==null) {
maps = new ArrayList<>();
}
HashMap<Object, Object> map1 = new HashMap<>();
map1.put("busiCodes",relienceValue);
maps.add(map1);

Set<Map.Entry<String, List<Map>>> entries = map.entrySet();
for (Map.Entry<String, List<Map>> entry : entries) {
String key = entry.getKey();
object.setTaskType(key);
object.setBusiCodes(entry.getValue());
noticeBpbc();
}*/
}

public static void b(){
Map<String,List<Map>> map = new HashMap<>();

List<Stu> stus = Arrays.asList(new Stu("0", "02"), new Stu("0", "04"), new Stu("1", "07"));
for (Stu stu : stus) {
List<Map> maps = map.get(stu.taskType);
if (maps==null) {
maps = new ArrayList<>();
}
map.put(stu.taskType,maps);

HashMap<Object, Object> busiCodesMap = new HashMap<>();
busiCodesMap.put("busiCodes",stu.relienceValue);
maps.add(busiCodesMap);
}

System.out.println("map:"+map);

A obj = new A();
Set<Map.Entry<String, List<Map>>> entries = map.entrySet();
for (Map.Entry<String, List<Map>> entry : entries) {
String key = entry.getKey();
obj.setTaskType(key);
obj.setBusiCodes(entry.getValue());
System.out.println("obj:"+obj);
}

}
}

标签:map,HashMap,list,listmap,maps,map1,new
来源: https://www.cnblogs.com/gendway/p/15022559.html