Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  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. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement