天天看點

兩個List合并的問題

public class PersonConfigVO {
    /**
     * 配置項唯一id
     */
    private String id;
    /**
     * 排序号
     */
    private Integer sort;
    /**
     * 描述資訊
     */
    private String label;
    /**
     * 圖示
     */
    private String icon;
    /**
     * 開關
     */
    private Boolean isActive;
}      
List<PersonConfigVO> list1 = JSON.parseArray(configEntity.getMenuField(), PersonConfigVO.class);
                List<PersonConfigVO> list2 = JSON.parseArray(systemConfig.getValue(), PersonConfigVO.class);
                Map<String, PersonConfigVO> map = new HashMap<>(8);
                for (PersonConfigVO configVO : list2) {
                    map.put(configVO.getId(), configVO);
                }
                for (PersonConfigVO configVO : list1) {
                    map.put(configVO.getId(), configVO);
                }
                List<PersonConfigVO> result=new ArrayList<>();
                for(Map.Entry<String,PersonConfigVO> configVOEntry: map.entrySet()){
                    result.add(configVOEntry.getValue());
                }