java 将List中的实体按照某个字段进行分组的算法

https://www.icode9.com/content-1-101353.html

    public Map> selectYlxMaterialManageList() {
        YlxMaterialManage query = new YlxMaterialManage();
        query.setDelFlag(YlxAdminConstant.DEL_FLAG_ZERO);
        query.setStatus(YlxAdminConstant.NORMAL_STATUS); //正常
        List selectList = ylxMaterialManageMapper.selectYlxMaterialManageList(query);

        Map> rstMap = new HashMap<>();

        for (YlxMaterialManage manage : selectList) {
            if (rstMap.containsKey(manage.getSortName())) {
                rstMap.get(manage.getSortName()).add(manage);
            } else {
                List tempList = new ArrayList<>();
                tempList.add(manage);
                rstMap.put(manage.getSortName(),tempList);
            }
        }

        return rstMap;
    }

你可能感兴趣的:(java 将List中的实体按照某个字段进行分组的算法)