public class LambadaTest {
public static void main(String[] args) {
Student s1 = new Student(“张三”,12);
Student s2 = new Student(“张2”,13);
Student s3 = new Student(“张四”,13);
Student s4 = new Student(“张5”,15);
List list = new ArrayList<>();
List list2 = new ArrayList<>();
list.add(s1);
list.add(s2);
list2.add(s3);
list2.add(s4);
list.addAll(list2);
// System.out.println(list.get(3).getName());
/**
* 1.遍历集合
*/
list.stream().forEach(item->{
System.out.println(item.getName());
});
/**
* 2.集合去重:单个字段(注意去重后是无序的)
*/
List<Student> newList = list.stream() .collect(
Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<Student>(Comparator.comparing(cn -> cn.getAge()))), ArrayList::new));
/**
-
3.根据对象属性排序(