fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. import java.util.stream.* ;
  8. import java.util.function.* ;
  9.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Ideone
  12. {
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15. List<String> words = Arrays.asList( "👋", "Welcome", "to", "the", "java", "world" );
  16.  
  17. Map < Character , Long > charFrequency =
  18. words
  19. .stream() //Stream<String>
  20. .flatMap( a -> a.chars().mapToObj( c -> (char) c ) ) // Stream<Character>
  21. .collect(
  22. Collectors.groupingBy( Function.identity(), Collectors.counting() )
  23. );
  24.  
  25. System.out.println( charFrequency ) ;
  26.  
  27. }
  28. }
Success #stdin #stdout 0.12s 51112KB
stdin
Standard input is empty
stdout
{a=2, c=1, d=1, e=3, h=1, j=1, ?=1, l=2, m=1, o=3, r=1, t=2, v=1, w=1, W=1, ?=1}