Here you can find the source of sortByLengthDesc(String[] ss)
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.
Parameter | Description |
---|---|
ss | array of strings |
public static void sortByLengthDesc(String[] ss)
//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); } }