ArrayUtils { public static void sortByLengthDescending( String[] strings ) { Arrays.sort( strings, new Comparator<String>() { @Override public int compare( String o1, String o2 ) { int len1 = o1.length(); int len2 = o2.length(); return ( len1 > len2 ? -1 : ( len1 == len2 ? 0 : 1 ) ); } } ); }  static String[] removeAll( String[] array, String token ); static String join( String delimiter, String... strings ); static String join( String delimiter, Object... objects ); static String join( String delimiter, Collection<?> objects ); static String join( String delimiter, int[] values ); static String join( String delimiter, double[] values ); static boolean contains( String[] target, String value, boolean caseSensitive, boolean exact ); static boolean contains( String[] target, String value ); static String[] toArray( String s, String delimiter, boolean deleteDoubles ); static List<String> toList( String s, String delimiter, boolean deleteDoubles ); static String[] deleteDoubles( String[] s ); static ArrayList<Integer> splitAsIntList( String str, String delim ); static double[] splitAsDoubles( String str, String delim ); static float[] splitAsFloats( String str, String delim ); static void sortByLengthDescending( String[] strings );  }
@Test public void sortStringsByLength() throws Exception { String[] strings = { "a", "ccc", "bb" }; sortByLengthDescending( strings ); assertArrayEquals( strings, new String[] { "ccc", "bb", "a" } ); }