日期:2014-05-20 浏览次数:20684 次
public class Sort {
/**
* @param args
*/
public static void main(String[] args) {
String s = "(1,2);20!(21,32);40!(50,60);40!(5,2);10!";
String[] arr = s.split("!");
Arrays.sort(arr, comparator);
for (String a : arr) {
System.out.print(a + "!");
}
}
static Comparator <String> comparator = new Comparator <String>() {
public int compare(String o1, String o2) {
return Integer.parseInt(o1.split(";")[1]) - Integer.parseInt(o2.split(";")[1]);
}
};
}