lambda表达式之list排序
lambda表达式常用的list排序 import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.List; import static java.util.Comparator.comparing; public class LambdaTest { public static void main(String[] args) { List<Person> personList = new ArrayList<>(); personList.addAll(Arrays.asList( new Person(12, 178, "张三2"), new Person(12, 176, "李四"), new Person(16, 180, "王五")) ); System.out.println(personList); //普通排序 personList.sort(new Comparator<Person>() { public int compare(Person a1, Person a2) { return a1.getAge().compareTo(a2.getAge()); } }); //lambda排序1 personList