2009/11/13 04:03 My major/JAVA
1. Create target class for sorting and define compareTo() function

class TargetClass implements Comparable{
  int id;
  String name;
  public TargetClass(int id, String name){
    id = id;
    name = name;
  }
  public int compareTo(Object o){
    TargetClass tc = (TargetClass)o;
    if(this.id > tc.id)
      return 1;
    else if(this.id == tc.id)
      return 0;
    else
      return -1;
  }
}

2. sort
public class mainClass{
  public static void main(String argv[]){
    Vector<TargetClass> vec = new Vector<TargetClass> ();
    for(int i=10; i>0; i--){
      TargetClass item = new TargetClass(i, "jo"+i);
      vec.add(item);
    }
    Collections.sort(vec);
  }
}
posted by joyoungtae
 <PREV 1 2 3 4 5 6 7 8 9 ... 311    NEXT>