I am trying to sort a 2D array based on the column and values but never got the result back as i want.
public class SortColl {
public static void main(String args[]){
String[][] multi = new String [][]{
{"Josef", "cool"},
{"Josef", "bat"},
{"zeta", "doen"},
{"zeta", "up"},
{"root", "local"},
{"root", "region"}
};
Arrays.sort(multi, new Comparator<String[]>(){
@Override
public int compare(String[] first, String[] second){
final String time1 = first[0];
final String time2 = second[0];
return time1.compareTo(time2);
}
});
for (int i=0; i< multi.length; i++){
String[] row = multi[i];
for(int j=0; j<row.length;j++){
System.out.println(" , " + row[j] );
}
}
}
}
For the above, I want to get the result as
{"Josef", "bat"},
{"Josef", "cool"},
{"root", "local"},
{"root", "region"}
{"zeta", "doen"},
{"zeta", "up"},
Can any one please guide me?
first[0]withsecond[0]. if the result is not 0, return the result of the comparation. But, if the result is 0, comparefirst[1]withsecond[1]and return the result of the other comparation