SHARE
TWEET

Untitled

a guest Feb 20th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class sortingtext {
  2.  
  3.     public static void main(String[] args) throws IOException {
  4.             String  readline="i have a sentence with words";
  5.             String[] words=readline.split(" ");
  6.  
  7.             Arrays.sort(words, (a, b)->Integer.compare(b.length(), a.length()));
  8.  
  9.             for (int i=0;i<words.length;i++)
  10.             {
  11.                 int len = words[i].length();
  12.  
  13.                 int t=0;
  14.  
  15.                 System.out.println(len +"-"+words[i]);
  16.             }
  17.  
  18.         }
  19.      
  20. final Map<Integer, List<String>> lengthToWords = new TreeMap<>(
  21.     Arrays.stream(words)
  22.         .collect(Collectors.groupingBy(String::length))
  23. );
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top