JUC练习12——流计算
作者:互联网
具体的使用参考:https://www.cnblogs.com/owenma/p/12207330.html
编写的代码示例:
/** * 使用stream完成下面要求: * 1,ID为偶数 * 2,年龄大于23 * 3,用户名转为大写字母 * 4,用户名倒排序 * 5,只输出一个用户 */ @Test public void test9() { User user1 = new User(1,"AAA",21); User user2 = new User(2,"BBB",22); User user3 = new User(3,"CCC",23); User user4 = new User(4,"DDD",24); User user5 = new User(6,"EEE",25); List<User> users = Arrays.asList(user1, user2, user3, user4, user5); users.stream(). filter((user) -> user.getId() % 2 == 0). filter(user -> user.getAge() > 23). map(u->u.getName().toUpperCase()). sorted(Comparator.reverseOrder()). limit(1). forEach(System.out::println); }
标签:JUC,12,user3,stream,23,练习,user,new,User 来源: https://www.cnblogs.com/chenjianjiang/p/15860183.html