fork(2) 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.  
  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.  
  16.  
  17. List < String > results =
  18. .stream(
  19. "aa1, aaaa, aaa, a12, a5, 44a44, 3232aa"
  20. .split( ", " )
  21. )
  22. .map(
  23. string ->
  24. string
  25. .codePoints() // Returns an `IntStream`
  26. .filter( Character :: isAlphabetic ) // Eliminate digits, punctuation, etc.
  27. .count()
  28. % 2 == 0 // Use modulo to test for even number.
  29. ? // Ternary operator.
  30. doEven() // returns a `String` object.
  31. :
  32. doOdd() // returns a `String` object.
  33. )
  34. .collect( Collectors.toList() )
  35. ;
  36.  
  37. System.out.println( results ) ;
  38. }
  39.  
  40. static String doEven() { return "even" ; }
  41.  
  42. static String doOdd() { return "odd" ; }
  43. }
Success #stdin #stdout 0.1s 49024KB
stdin
Standard input is empty
stdout
[even, even, odd, odd, odd, odd, even]