目录

lambdagroupingBy对数据做map转换

目录

lambda:groupingBy对数据做map转换

示例代码:

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

// 假设的 EfloTypeTVo 类
class EfloTypeTVo {
    private String lxLeofType;
    private String lxEploType;
    private String descr;

    public EfloTypeTVo(String lxLeofType, String lxEploType, String descr) {
        this.lxLeofType = lxLeofType;
        this.lxEploType = lxEploType;
        this.descr = descr;
    }

    public String getLxLeofType() {
        return lxLeofType;
    }

    public String getLxEploType() {
        return lxEploType;
    }

    public String getDescr() {
        return descr;
    }
}

public class Main {
    public static void main(String[] args) {
        // 模拟数据
        List<EfloTypeTVo> data = Arrays.asList(
                new EfloTypeTVo("type1", "reason1", "description1"),
                new EfloTypeTVo("type1", "reason2", "description2"),
                new EfloTypeTVo("type2", "reason3", "description3")
        );

        // 合成代码
        Map<String, Map<String, String>> result = data.stream()
               .collect(Collectors.groupingBy(
                        EfloTypeTVo::getLxLeofType,
                        Collectors.toMap(
                                EfloTypeTVo::getLxEploType,
                                EfloTypeTVo::getDescr,
                                (k1, k2) -> k1
                        )
                ));

        // 输出结果
        System.out.println(result);
    }
}