二维数组的排序可以利用Comparator接口来实现。
int[][] graph = new int[100][2]; for(int i = 0;i < 100;i++){ graph[i][0] = (int)(Math.random() * 1000); graph[i][1] = (int)(Math.random() * 1000); } Arrays.sort(graph, new Comparator<int []>() { @Override public int compare(int[] a, int[] b){ if(a[0] == b[0]) return a[1] - b[1]; return a[0] - b[0]; } }); for(int i = 0;i < graph.length;i++){ for(int j = 0;j < 2;j++){ System.out.print(graph[i][j] + " "); } System.out.println(); }