select * from person where age=21 List<Person> personList2= personList.stream().filter(x->x.getAge()==21).collect(Collectors.toList()); select Name from Person where salary=8000 List<String> fiterList = personList.stream().filter(x -> x.getSalary() > 8000).map(Person::getName) .collect(Collectors.toList()); SELECT * FROM User ORDER BY age DESC LIMIT 1;/ / 使用stream和max方法找到年龄最大的User Optional<User> maxAgeUser = users.stream().max(Comparator.comparingInt(User::getAge)); // 如果存在年龄最大的User,则打印出其信息 maxAgeUser.ifPresent(user ->System.out.println("User with max age: " + user)); } // 使用stream和max方法找到名字最长的 User Optional<User> maxNameLengthUser = users.stream().max(Comparator.comparingInt(user -> user.getName().length())); // 如果存在名字最长的User,则打印出其信息 maxNameLengthUser.ifPresent(user -> System.out.println("User with max name length: " + user)); Optional<Person> max=personList.stream().max(Comparator.comparingInt(Person::getSalary) System.out.println("员工薪资最大值:" + max.get().getSalary());
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/mu_wind/article/details/109516995