fork download
  1. import java.util.Map;
  2. import java.util.function.Function;
  3. import java.util.stream.Collectors;
  4. import java.util.stream.Stream;
  5.  
  6. public class Main {
  7. public static void main(String[] args) throws Exception {
  8.  
  9. String[] data = ("Now, this is a story all about how\n" +
  10. "My life got flipped-turned upside down\n" +
  11. "And I'd like to take a minute\n" +
  12. "Just sit right there\n" +
  13. "I'll tell you how I became the prince of a town called Bel Air").replaceAll("[,.\r\n]", " ").split(" +");
  14.  
  15. Map<Integer, String> collect = Stream.of(data)
  16. .collect(Collectors.toMap(String::length, Function.identity(), (s1, s2) -> s1 + "," + s2));
  17. System.out.println(collect);
  18. }
  19. }
  20.  
Success #stdin #stdout 0.1s 37116KB
stdin
Standard input is empty
stdout
{1=a,a,I,a, 2=is,My,to,of, 3=Now,all,how,got,And,I'd,sit,you,how,the,Bel,Air, 4=this,life,down,like,take,Just,I'll,tell,town, 5=story,about,right,there, 6=upside,minute,became,prince,called, 14=flipped-turned}