以String[]的list集合为例:先按第一列排序,再按第二类排序。
package java_demo;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class Test22 {
public static void main(String[] args) {
List<String[]> list = new ArrayList<String[]>();
list.add(new String[] { "100", "2" });
list.add(new String[] { "100", "3" });
list.add(new String[] { "101", "2" });
list.add(new String[] { "101", "5" });
list.add(new String[] { "100", "4" });
list.add(new String[] { "101", "3" });
list.add(new String[] { "100", "6" });
System.out.println("排序之前:");
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i)[0]+" "+list.get(i)[1]);
}
Collections.sort(list, new Comparator<String[]>()