java8 stream map转化为list
原创
©著作权归作者所有:来自51CTO博客作者chushiyunaaa的原创作品,请联系作者获取转载授权,否则将追究法律责任
java8操作起来是非常的流畅简单啊,代码如下:
@Data
public class Account {
private String username;
private Integer money;
public Account() {
}
public Account(String username, Integer money) {
this.username = username;
this.money = money;
}
public static void main(String[] args) {
HashMap<String, Integer> map = new HashMap<>();
map.put("mayun",2000);
map.put("mahuateng",1200);
map.put("liuqiangdong",700);
List<Account> collect = map.entrySet().stream().map(en -> new Account(en.getKey(), en.getValue())).collect(Collectors.toList());
collect.stream().forEach(n-> System.out.println(n));
}
}