map转list对象方法,通过stream或者iterator.key集合转list,values集合转list

// key 转 List
List keyList = new ArrayList<>(map.keySet());
List keyList2 = map.keySet().stream().collect(Collectors.toList());

// value 转 List
List valueList = new ArrayList<>(map.values());
List valueList2 = map.values().stream().collect(Collectors.toList());


// Iterator转List
List keyValueList = new ArrayList<>();
Iterator it = map.keySet().iterator();
while (it.hasNext()) {
	Integer k = (Integer) it.next();
	keyValueList.add(new KeyValue(k, map.get(k)));
}
// Java8 Stream
List list = map.entrySet().stream().map(c -> new KeyValue(c.getKey(), c.getValue())).collect(Collectors.toList());

业务场景转ICEDMemberVO对象:

方法一通过stream:

List result = icedMemberManagementVOS.entrySet().stream().map(c -> new ICEDMemberVO(c.getKey(), c.getValue())).collect(Collectors.toList());

方法二,迭代

List result = new ArrayList<>();
Iterator>> iterator = icedMemberManagementVOS.entrySet().iterator();
while (iterator.hasNext()){
    Map.Entry> next = iterator.next();
    ICEDMemberVO icedMemberVO = new ICEDMemberVO(next.getKey(), next.getValue());
    result.add(icedMemberVO);
}

对象实体类:

@Data
public class ICEDMemberVO {

    //**成员id**//
    private Integer userId;

    /**内容**/
    List icedMemberManagementVOS;

    public ICEDMemberVO(Integer key, List value) {
        this.userId = key;
        this.icedMemberManagementVOS = value;
    }
}

你可能感兴趣的:(java,mybatis,jvm)