jdk1.8 List排序

List users=new ArrayList();

组合排序 先按name排序,name相同的按age排序

Collections.sort(users,Comparator.comparing(User::getName).thenComparing(User::getAge));

降序

Collections.sort(users, Comparator.comparing(User::getUserId).reversed());

升序

users.sort((x,y)->x.getUserId().compareTo(y.getUserId()));

 

你可能感兴趣的:(java)