Here is a complete example:
import java.util.*;
class Class1 {
String s;
int[] s1;
int soc;
public Class1(String s, int[] s1, int soc) {
this.s = s;
this.s1 = s1;
this.soc = soc;
}
public String toString() { return String.format("s: %s soc: %d", s, soc); }
}
public class Test {
public static void main(String... args) {
List<Class1> list = new ArrayList<Class1>();
list.add(new Class1("abcd", new int[] {1}, 3));
list.add(new Class1("efgh", new int[] {2}, 5));
list.add(new Class1("ijkl", new int[] {8}, 9));
list.add(new Class1("mnop", new int[] {3}, 7));
Collections.sort(list, new Comparator<Class1>() {
public int compare(Class1 o1, Class1 o2) {
return o1.soc > o2.soc ? -1 : o1.soc == o2.soc ? 0 : 1;
}
});
System.out.println(list.toString().replaceAll(",", "\n"));
}
}
It prints the following:
[s: ijkl soc: 9
s: mnop soc: 7
s: efgh soc: 5
s: abcd soc: 3]