Please help, I'm having trouble how to sort Array of Strings in two columns. So, I have two columns: Both of it contains a string. I need to sort the first column in alphabetical order while the second column should not shuffle, thus, it should correspond to the first column after sorting.
Can anyone see where I need to put sorting method in my code below:
public static void main(String[] args) {
String[][] emp = {
{"Victor ", "ZSA"},
{"Fred ", "HAN"},
{"Drake ", "SOL"},
{"Albert ", "TUR"},
{"Eric ", "CAN"}};
System.out.println("String 1: String 2: ");
for (int i = 0; i < emp.length; i++) {
for (int j = 0; j < emp[0].length; j++) {
System.out.printf("%9s", emp[i][j]);
}
System.out.println();
}
}
the output should be:
Albert TUR
Drake SOL
Eric CAN
Fred HAN
Victor ZSA