I want to sort the items in my list with a predefined order....Is it possible? I can sort my List using a natural sort as in the below example. But that is not am looking for.....Am looking for sorting my list using an already defined order which i can hold using another list. IS IT POSSIBLE USING Comparator
import java.util.*;
public class TestUsingMe {
static class AppComparator implements
Comparator {
public int compare(Object o1, Object o2) {
int cc = ((Integer)o1).compareTo(o2);
return (cc < 0 ? 1 : cc > 0 ? -1 : 0);
}
}
static Comparator appcomparator =
new AppComparator();
static void sort(List list1) {
Collections.sort(list1, appcomparator);
}
public static void main(
String[] args) {
List list1 = new ArrayList();
list1.add(new Integer(90));
list1.add(new Integer(43));
list1.add(new Integer(21));
sort(list1);
System.out.println(list1);
}
}
Please reply................
[ June 05, 2006: Message edited by: suresh saro ]
[ June 09, 2006: Message edited by: suresh saro ]