对List进行自定义顺序排序
,打个比方,现在我有一个SortStudent类,需要对它的年龄降序排序,再对他的省份进行自定义的排序,要求按照:“安徽”, “北京”, “上海”, “深圳”, "广州"的顺序排列,如何实现呢?直接上代码,很简单,关键地方有注释,应该是一目了然的。
public class CustomSort {
private static final List<String> regulationOrder = Arrays.asList("安徽", "北京", "上海", "深圳", "广州");
public static void main(String[] args) {
List<SortStudent> students = new ArrayList<>();
SortStudent student1 = new SortStudent("Mike", 5, "上海");
SortStudent student2 = new