fork(2) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone
  6. {
  7. public static String[] cleanArray(String[] array) {
  8. return Arrays.stream(array).filter(x -> x!=null & !x.equals("")).toArray(String[]::new);
  9. }
  10.  
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. String text="red 1 green 3 blue";
  14. System.out.println(Arrays.toString(text.split("red|green|blue")));
  15. System.out.println(Arrays.toString(text.split("red|green|blue", -1)));
  16. System.out.println(Arrays.toString(cleanArray(text.split("red|green|blue"))));
  17. }
  18. }
Success #stdin #stdout 0.08s 34328KB
stdin
Standard input is empty
stdout
[,  1 ,  3 ]
[,  1 ,  3 , ]
[ 1 ,  3 ]