Java Array Sort sortByLengthDesc(String[] ss)

Here you can find the source of sortByLengthDesc(String[] ss)

Description

Sorts an array of strings by their length in descending order.

This sort is guaranteed to be stable: strings of equal length are not reordered.

License

BSD License

Parameter

Parameter Description
ss array of strings

Declaration

public static void sortByLengthDesc(String[] ss) 

Method Source Code

//package com.java2s;
//License from project: BSD License 

import java.util.Arrays;
import java.util.Comparator;

public class Main {
    /**//from   w  w  w  .jav  a  2s  .  c  om
     * <p>Sorts an array of strings by their length in descending order.</p>
     * 
     * <p>This sort is guaranteed to be stable: strings of equal length are not
     * reordered.</p>
     * 
     * @param ss array of strings
     */
    public static void sortByLengthDesc(String[] ss) {
        Comparator<String> lengthC = new Comparator<String>() {
            public int compare(String s1, String s2) {
                return s2.length() - s1.length();
            }
        };

        Arrays.sort(ss, lengthC);
    }
}

Related

  1. sortByFirst(int[] array1, int[] array2)
  2. sortByIndex(final double[] data, int size)
  3. sortByIndex(int start, int end, int[] indexes, double[] values)
  4. sortByIndex(int start, int end, int[] indexes, double[] values)
  5. sortByLength(String[] proposals)
  6. sortByString(Object[] array)
  7. sortByValue(int start, int end, double[] values, int[] indexes)
  8. sortByValueStable(int start, int end, double[] values, int[] indexes)
  9. sortCompare(String[] valuesOne, String[] valuesTwo)