我想对多维字符串数组进行冒泡排序,但它似乎不起作用
public class Array {
public static void main( final String args[] ) {
final String[][] arrDataIn =
{
{ "abc", "9", "5" },
{ "xyz", "3", "4" },
{ "lmn", "7", "3" },
{ "hij", "1", "3" }
};
final Array bs = new Array();
final String arrSorted[][] = bs.sort( arrDataIn, 0, 1 );
for ( int y = 0; y < arrSorted.length; y++ ) {
System.out.println( "Printing Row Number :" + y );
for ( int z = 0; z < arrSorted[y].length; z++ )
System.out.println( "Value : " + arrSorted[y][z] );
}
}
public String[][] sort( final String arrDataIn[][], final int iCol, final int iOrder ) {
final String arrTmp[] = new String[ arrDataIn[0].length ];
for ( int z = 0; z < arrDataIn.length; z++ ) {
for ( int i = 0; i < arrDataIn.length - ( z + 1 ); i++ ) {
if ( arrDataIn[i].compareTo( arrDataIn[i + 1] ) < 0 ) {
for ( int j = 0; j < arrDataIn[i].length; j++ ) {
arrTmp[j] = arrDataIn[i][j];
arrDataIn[i][j] = arrDataIn[i + 1][j];
}
for ( int m = 0; m < arrTmp.length; m++ )
arrDataIn[i + 1][m] = arrTmp[m];
} else if ( arrDataIn[i].compareTo( arrDataIn[i + 1] ) < 0 ) {
for ( int j = 0; j < arrDataIn[i].length; j++ ) {
arrTmp[j] = arrDataIn[i][j];
arrDataIn[i][j] = arrDataIn[i + 1][j];
}
for ( int m = 0; m < arrTmp.length; m++ )
arrDataIn[i + 1][m] = arrTmp[m];
}
}
}
return arrDataIn;
}
}
输出错误显示:
error: cannot find symbol
if (arrDataIn[i].compareTo(arrDataIn[i+1])<0)
^
symbol: method compareTo(String[])
location: class String[]
error: cannot find symbol
else if (arrDataIn[i].compareTo(arrDataIn[i+1])<0)
^
symbol: method compareTo(String[])
location: class String[]
我尝试将其更改为:
if (arrDataIn[i][iCol] > arrDataIn[i+1][iCol] && (iOrder == 0))
else if (arrDataIn[i][iCol] < arrDataIn[i+1][iCol] && (iOrder == 1))
它仍然是同样的错误