Heim >Java >javaLernprogramm >Listensortierung
package demo.main; import java.util.Comparator; public class PersonComparator implements Comparator<Object>{ public int compare(Object arg0, Object arg1) { Person user0=(Person)arg0; Person user1=(Person)arg1; //首先比较名字,如果名字相同,则比较工资 int flag=user0.getName().compareTo(user1.getName()); if(flag==0){ return user0.getWages().compareTo(user1.getWages()); }else{ return flag; } } }