I have an arraylist of String[]:
ArrayList< String [] > mystuff = new ArrayList < String [] > ();
I want to sort them in largest-array-size ascending order. Example:
mystuff = {[“this”, “is”, “item”,
“one”], [“this”, “is”, “item”, “two”],
[“item”], [“item”, “three”]}
Should become:
mystuff = {[“item”], [“item”,
“three”], [“this”, “is”, “item”,
“one”], [“this”, “is”, “item”, “two”]}
For arrays of equal length, the order doesn’t matter.
Edit:
Java compiler version: javac 1.6.0_20
Error that I am facing by using
@sepp2k’s code:
http://pastie.org/private/ienpdtj0ft6czw6nboeva
Use
Collections.sortwith aComparatorthat compares the length.Edit: Here’s a complete class that compiles and runs without error (and shows the correct result):