fork(1) download
  1. import java.util.Arrays;
  2.  
  3. /**
  4.  * https://stackoverflow.com/questions/45276416/java-split-not-working-as-expected-for-string
  5.  */
  6. class JavaSplitTest
  7. {
  8. // arguments are passed using the text field below this editor
  9. public static void main(String[] args)
  10. {
  11. String searchValue = "Hi Hello this is -- to test\n" +
  12. "\n" +
  13. "--\n" +
  14. "\n" +
  15. "java split function -- test\n";
  16.  
  17. String[] splitted = searchValue.split("\n--\n");
  18.  
  19. System.out.println(Arrays.asList(splitted));
  20. }
  21. }
  22.  
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
[Hi Hello this is -- to test
, 
java split function -- test
]