package com.gp6.list.sort;
import com.gp6.bean.Employee;
import com.gp6.list.utils.ListUtil;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
/**
* list 排序
*
* @author gp6
* @date 2019-07-23
*/
public class TestSort {
public static void main(String[] args) {
List<Employee> employeeList = ListUtil.packEmployeeList();
// 根据 id(类型:int) 排序
List<Employee> idSortList = employeeList.stream().sorted(Comparator.comparingInt(Employee::getId)).collect(Collectors.toList());
idSortList.forEach(employee -> {
});
// 根据 薪资(类型:long) 排序
List<Employee> salarySortList = employeeList.stream().sorted(Comparator.comparingLong(Employee::getSalary)).collect(Collectors.toList());
salarySortList.forEach(employee -> {
});
}
}
7 排序(sorted)
最新推荐文章于 2024-05-20 18:53:03 发布