This is for row based sorting
Before sorting: array[2][n]
5 4 3 2 1..
3 4 5 9 0..
After sorting:
1 2 3 4 5..
0 9 5 4 3..
i.e Array should be sorted using 1st row alone in ascending order and corresponding column values should change accordingly as shown in above result.
Guide me how this can be generated using Arrays.sort(a, new Comparator() function?
int rowcount= jTable1.getRowCount();
int j;
int parr[][] = new int[10][10];
for(j=0; j<rowcount; j++)
{
parr[0][j]= Integer.parseInt(jTable1.getValueAt(j, 2).toString());
parr[1][j]= Integer.parseInt(jTable1.getValueAt(j, 1).toString());
}
System.out.println("Before sorting");
for(j=0; j<rowcount; j++)
{
System.out.println(parr[0][j]);
}
for(j=0; j<rowcount; j++)
{
System.out.println(parr[1][j]);
}
System.out.println("After sorting");
Arrays.sort(parr, new Comparator<int[]>()
{
@Override
public int compare(int[] o1, int[] o2)
{
return Integer.compare(o2[1], o1[1]);
}
}
);
for(j=0; j<rowcount; j++)
{
System.out.println(parr[0][j]);
}