zoukankan      html  css  js  c++  java
  • 777

    package Collections.sort;
    
    import java.util.Comparator;
    
    public class Employee implements Comparable<Employee>{
    	int id;
    	String name;
    	int age;
    	
    	public Employee(int id, String name,int age) {
    		super();
    		this.id = id;
    		this.name = name;
    		this.age=age;
    	}
    
    	@Override
    	public int compareTo(Employee o) {
    		int result=this.id-o.id;
    		int result2=this.age-o.age;
    		if(result!=0){
    			return result;
    		}else if(result2!=0){
    			return result2;
    		}else{
    			return this.name.compareTo(o.name);
    		}
    	}
    
    	@Override
    	public String toString() {
    		return "Employee [id=" + id + ", name=" + name + ", age=" + age + "]";
    	}
    	
    	//内部类     根据id的比较结果进行排序
    	static class IdComparator implements Comparator<Employee>{
    		@Override
    		public int compare(Employee o1, Employee o2) {
    //			return o1.id.compareTo(o2.id);
    			return o1.id-o2.id;
    		}		
    	}
    	
    	
    	
    	
    }
     
    

      

  • 相关阅读:
    linux 文件类型 文件权限
    微信公众号支付
    struts2 详解
    git 命令行操作
    javascript 闭包
    SVN 基本操作
    javascript 函数 方法
    git
    javascript变量 数组 对象
    Intellij调试debug
  • 原文地址:https://www.cnblogs.com/1020182600HENG/p/6724396.html
Copyright © 2011-2022 走看看