Can any one help me in sorting a 2 Dimensional Array
Which will have the data in the following format
[2, All are fine]
[4, All is Well]
[1, Welcome Code]
[9, Javascript]
After sorting it should look like
[2, All are fine]
[4, All is Well]
[9, Javascript]
[1, Welcome Code]
Main thing that i am focussing is to sort based on Text not on the ID
To sort all elements of a 2D array by row-wise. As in the above rewrite program, the sort() method is used to iterate each element of a 2D array and sort the array row-wise. Finally, the print method displays all the elements of the 2D array.
In Java, a 2D array can be sorted row-wise or column-wise as per requirements. For row-wise sorting, only the Array. sort() method is utilized; however, in column-wise sorting, the Array. sort() method is called with the Comparator interface.
No, it's not. In some languages, you can have multidimensional arrays like string[3,5] = "foo"; .
ary.sort(function(a, b) { return (a[1] < b[1] ? -1 : (a[1] > b[1] ? 1 : 0)); });
See: http://jsfiddle.net/tdBWh/ for this example, and MDC for documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With