0

I'm trying to split String by lines. The problem is I'm unable to split last lines if they're empty.

For example if input String is like this:

asd\n\na\n\n\n

I use split like this:

Split(String input) {

    List<String> list = new ArrayList<String>(Arrays.asList(input.split("\n")));
    GWT.log("How many lines: "+list.size());

}

I get How many lines: 3 on the logs, although it has to be 5. Last two blank lines is not being split. What am I missing?

B. Hurray
  • 382
  • 4
  • 16
  • 1
    Actually, your answer is here: https://stackoverflow.com/questions/14602062/java-string-split-removed-empty-values (which is very cool, because I did not know that.) – Mike Nakis May 28 '17 at 18:51
  • 2
    @MikeNakis Thanks, `input.split("\n", -1)` worked! – B. Hurray May 28 '17 at 18:53

0 Answers0