編集:キャンパラータを使用してみましたが、うまくいきませんでした。エラーが発生しました
内容を含むファイルを読み込む必要があります
2011 Regular Season
Boston 162 5710 875 1600 352 35 203
NY_Yankees 162 5518 867 1452 267 33 222
Texas 162 5659 855 1599 310 32 210
Detroit 162 5563 787 1540 297 34 169
St.Louis 162 5532 762 1513 308 22 162
Toronto 162 5559 743 1384 285 34 186
Cincinnati 162 5612 735 1438 264 19 183
Colorado 162 5544 735 1429 274 40 163
Arizona 162 5421 731 1357 293 37 172
Kansas_City 162 5672 730 1560 325 41 129
これは私がそれを読んだコードです
static String specstat[][] = new String[1000][1000];
public static void main(String args[]) {
Arrays.sort(specstat, new Comparator<String[]>() {
@Override
public int compare(final String[] entry1, final String[] entry2) {
final String time1 = entry1[0];
final String time2 = entry2[0];
return time1.compareTo(time2);
}
});
for (final String[] s : specstat) {
System.out.println(s[0] + " " + s[0]);
}
execute();
}
public static String[][] execute() {
int line = 0;
try {
BufferedReader in = new BufferedReader(new FileReader(
"files/input.txt"));
String str;
while ((str = in.readLine()) != null) {
if (str.trim().length() == 0) {
continue; // Skip blank lines
}
specstat[line] = str.split("\\s+");
line++;
}
in.close();
} catch (IOException e) {
System.out.println("Can not open or write to the file.");
}
return specstat;
}
テキスト ファイルの最後の (または任意の) 列の最初の列に基づいて 2D 配列を並べ替えるにはどうすればよいですか?