Sort words by the reverse length(i.e., from the longest to the shortest length ) of each word. - Java Lambda Stream

Java examples for Lambda Stream:Lambda

Description

Sort words by the reverse length(i.e., from the longest to the shortest length ) of each word.

Demo Code


import java.util.Collections;
import java.util.List;

public class Main {
  /**//from ww  w.  ja v  a 2  s  . c  o  m
   * Sort words by the reverse length(i.e., from the longest to the shortest
   * length ) of each word.
   * 
   * @return
   */
  public static List<String> sortWordsByReverseLength(List<String> nWords) {

    // sort non-null nWords IN PLACE using Collections.sort
    // Put your code here! ...
    Collections.sort(nWords, (o1, o2) -> {

      return o2.length() - o1.length();
    });
    return nWords;
  }
}

Related Tutorials