fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.util.stream.*;
  5. import java.util.stream.Collectors.*;
  6. import java.util.regex.*;
  7. import java.lang.*;
  8. import java.io.*;
  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> data = Arrays.asList( "a", "12", "b", "34", "c", "38", "d", "21", "19", "1" );
  16. Map<Character,Integer> digCount = data.stream()
  17. .filter(Pattern.compile("\\d+").asPredicate())
  18. .collect(Collectors.groupingBy(s -> s.charAt(0), Collectors.summingInt(s->1)));
  19. for (Map.Entry<Character,Integer> e : digCount.entrySet()) {
  20. System.out.println(e.getKey()+" "+e.getValue());
  21. }
  22. }
  23. }
Success #stdin #stdout 0.23s 34268KB
stdin
Standard input is empty
stdout
1 3
2 1
3 2