So I have a 2d array In Java that is a String
String a[][] = new String[3][4];
a[0][0] = "John";
a[0][1] = "Doe";
a[0][2] = "B";
a[0][3] = "999";
a[1][0] = "Bob";
a[1][1] = "Smith";
a[1][2] = "Q";
a[1][3] = "420";
a[2][0] = "Name";
a[2][1] = "Here";
a[2][2] = "T";
a[2][3] = "123";
How would I go about sorting the rows alphabetically?
I tried Arrays.sort(a)
, but it just threw back errors. And I feel like its gonna be more complicated that.
The output should be:
Bob Smith Q 420
John Doe B 999
Name Here T 123
I already have the code for printing it working properly, just need to sort it alphabetically by rows.