- // key 转 List
- List<Integer> keyList = new ArrayList<>(map.keySet());
- List<Integer> keyList2 = map.keySet().stream().collect(Collectors.toList());
- // value 转 List
- List<String> valueList = new ArrayList<>(map.values());
- List<String> 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;
- }
- }