Java8 利用Lambda处理List集合

List<User> list = new ArrayList<User>();
        User user1 = new User("第一位","用户1");
        list.add(user1);
        User user2 = new User("第二位","用户2");
        list.add(user2);
        User user3 = new User("第三位","用户3");
        list.add(user3);
        List<String> tableNames=list.stream().map(User::getMessage).collect(Collectors.toList());
        System.out.println("输出第一个:"+tableNames);
        List<String> orders=list.stream().map(User::getOrder).collect(Collectors.toList());
        System.out.println(orders)
posted @ 2018-08-06 15:24  小锋神  阅读(13636)  评论(0编辑  收藏  举报