fork download
  1. import java.util.*;
  2. import java.lang.*;
  3.  
  4. import java.io.*;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String text = "Apple Dog Apple\nDog Orange Dog";
  11. List<String> list = new ArrayList<>();
  12. for (String line: text.split("\n")) {
  13. Arrays.stream(line.split(" "))
  14. .filter(i -> i.substring(0,1).matches("[AaEeUuIiOoYy]"))
  15. .forEach(list::add);
  16. }
  17. System.out.println(list);
  18. }
  19. }
Success #stdin #stdout 0.09s 48828KB
stdin
Standard input is empty
stdout
[Apple, Apple, Orange]