java集合进行排序的两种方式java 集合的工具类 Collections 中提供了两种排序的方法 分别是 Collections sort List list Collections sort List list Comparator c 第一种称为自然排序 参与排序的对象需实现 comparable 接口 重写其 compareTo 方法 方法体中实现对象的比较大小规则 示例如下 实体类 基本属性
java集合的工具类Collections中提供了两种排序的方法,分别是:
Collections.sort(List list)
Collections.sort(List list,Comparator c)
第一种称为自然排序,参与排序的对象需实现comparable接口,重写其compareTo()方法,方法体中实现对象的比较大小规则,示例如下:
实体类:(基本属性,getter/setter方法,有参无参构造方法,toString方法)
package com.zgljl2012.activemq.example1;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Emp implements Comparable