我有这个2维字符串数组。基于整数的2维字符串数组排序
2 10 BakerSarah D
2 11 SmothersSally A
2 12 SillySall C
2 13 Viper B
2 5 LouieChef B
2 6 Lawson C
每列都是字符串。现在我想在第二栏中进行分类。我曾尝试这个代码
void sortarray(final int index){
Arrays.sort(data, new Comparator<Object[]>(){
@Override
public int compare(Object[] o1, Object[] o2) {
String[] a = (String[])o1;
String[] b = (String[])o1;
return a[index].compareTo(b[index]);
}
});
}
,但这样做是为了给排序在
2 10 BakerSarah D
2 11 SmothersSally A
2 12 SillySall C
2 13 Viper B
2 5 LouieChef B
2 6 Lawson C
。为什么这样 ?? 如何更改排序
2 5 LouieChef B
2 6 Lawson C
2 10 BakerSarah D
2 11 SmothersSally A
2 12 SillySall C
2 13 Viper B
你想整数排序,但你的值仍然是一个字符串,你需要将它转换为整数,并比较整数 – x4rf41