Home > Java > javaTutorial > body text

List sorting

巴扎黑
Release: 2016-12-28 17:57:41
Original
1693 people have browsed it

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;
 }  
}
 
 
}
Copy after login

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!