fork(2) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.util.regex.*;
  5. import java.util.stream.*;
  6. import java.lang.*;
  7. import java.io.*;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14.  
  15.  
  16. Pattern pattern = Pattern.compile(", ");
  17. List<String> f = pattern.splitAsStream("Red apple, blue banana, orange")
  18. .map(s -> {
  19. String[] parts = s.split(" ");
  20. return parts.length == 2
  21. ? parts[0].toUpperCase()+"_"+parts[1].toUpperCase()
  22. : s;
  23. }).collect(Collectors.toList());
  24. for (String s : f) {
  25. System.out.println(s);
  26. }
  27.  
  28. }
  29. }
Success #stdin #stdout 0.13s 4386816KB
stdin
Standard input is empty
stdout
RED_APPLE
BLUE_BANANA
orange