关于java中的对象排序

package sort;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Objectsort implements  Comparable {
	
	  private int id;
	  private String username;
	  private int age;
	  public Objectsort()
	  {
		  super();
	  }
	  public Objectsort(int id,String username,int age)
	  {
		  super();
		  this.id=id;
		  this.username=username;
		  this.age=age;
		  
		  
		  
	  }
	
	@Override
	public int compareTo(Object o) {
		// TODO Auto-generated method stub
		Objectsort os=(Objectsort) o;
		if(this.id>os.id)
		{
			return 1;
		}
		else if(this.idos.age)
			{
				return 1;
			}
			else if(this.age list=new ArrayList();
    list.add(new Objectsort(1, "陕西二杆子", 18));
    list.add(new Objectsort(2, "陕西二杆子1", 9));
    list.add(new Objectsort(2, "陕西二杆子2", 21));
    list.add(new Objectsort(4, "陕西二杆子3", 0));
    list.add(new Objectsort(0, "陕西二杆子4", 12));
    Collections.sort(list);
    for(Objectsort user : list){
        System.out.println(user);
    }
	}
}

你可能感兴趣的:(我的算法之路,排序,对象)