自定义Student类
1、筛选年龄集合
List<Student> paramList = new ArrayList<>(); List<Integer> resultList = paramList.stream().map(Student::getAge).collect(Collectors.toList());
2、筛选姓名集合
List<Student> paramList = new ArrayList<>(); List<String> resultList = paramList.stream().map(Student::getName).collect(Collectors.toList());
3、根据年龄升序
I、 List<Student> paramList = new ArrayList<>(); paramList.sort(new Comparator<Student>() { @Override public int compare(Student o1, Student o2) { return o1.getAge() - o2.getAge(); } });
II、
List<Student> paramList = new ArrayList<>(); paramList.sort((o1, o2) -> o1.getAge() - o2.getAge());
III、
List<Student> paramList = new ArrayList<>(); paramList.sort(Comparator.comparingInt(Student::getAge));
4、根据年龄降序
I、
List<Student> paramList = new ArrayList<>(); paramList.sort(new Comparator<Student>() { @Override public int compare(Student o1, Student o2) { return o2.getAge() - o1.getAge(); } });
II、
List<Student> paramList = new ArrayList<>(); paramList.sort((o1, o2) -> o2.getAge() - o1.getAge());
这些都是jdk自带的一些方法,字面意思是比较容易理解的,就不做过多说明了,有问题的欢迎留言