Home >Java >javaTutorial >List sorting

List sorting

巴扎黑
巴扎黑Original
2016-12-28 17:57:411746browse

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;
 }  
}
 
 
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn