200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > java将Map转换为List

java将Map转换为List

时间:2018-11-17 14:18:54

相关推荐

java将Map转换为List

实例

List<BlogComment> blogCommentListResult = new ArrayList<>(blogCommentMap.values());

Map数据转换为自定义对象的List,例如把map的key,value分别对应Person对象两个属性:

List<Person> list = map.entrySet().stream().sorted(paring(e -> e.getKey())).map(e -> new Person(e.getKey(), e.getValue())).collect(Collectors.toList());List<Person> list = map.entrySet().stream().sorted(paring(Map.Entry::getValue)).map(e -> new Person(e.getKey(), e.getValue())).collect(Collectors.toList());List<Person> list = map.entrySet().stream().sorted(paringByKey()).map(e -> new Person(e.getKey(), e.getValue())).collect(Collectors.toList());

以上三种方式不同之处在于排序的处理

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。