代码行业日新月异,不get点新技能都快要被淘汰了,今天第一次写lambda表达式,在此记录一下。
public class Test {
@Data
static class Person{
private String name;
private Integer age;
public Person(String name, Integer age){
this.age = age;
this.name = name;
}
}
public static void main(String[] args){
Person person = new Person("tom", 8);
Person person1 = new Person("jack", 5);
List<Person> personList = new ArrayList<>();
personList.add(person);
personList.add(person1);
Collections.sort(personList, (Person o1, Person o2) -> (o1.age - o2.age));
System.out.println(personList);
}
}