• 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);
    }

    }
    }
  • 相关阅读:
    第二阶段冲刺第七天,6月6日。
    第二阶段冲刺第六天,6月5日。
    第二阶段冲刺第五天,6月4日。
    第二阶段冲刺第四天,6月3日。
    第二阶段冲刺第三天,6月2日。
    第二阶段冲刺第二天,6月1日。
    垃圾收集器与内存分配策略(1)
    OutOfMemoryError异常
    对象访问
    java内存区域与内存溢出异常(2)
  • 原文地址:https://www.cnblogs.com/gendway/p/15022559.html
Copyright © 2020-2023  润新知