0

Can someone tell me if the regular expression for just a new line was changed from java 7 to java 8?

In Java 7 it seems String.split("\\\\n") is correct, however using an online compiler/runner for a coding challenge in Java 8 this did not work, istead I had to use "\n".

DAnsermino
  • 363
  • 4
  • 17
  • 1
    Voting to close as non-reproducible. Using [this fairly old-looking website](http://www.browxy.com/) which still uses a Java 7 runtime, and comparing to (and copying) the code [on this newer, Java 8 website](https://ideone.com/U780NK) demonstrates that there's no difference between `\\\\n` and `\n`. – hnefatl Nov 18 '17 at 22:55
  • 1
    @hnefatl: your test case is not able to tell whether the pattern worked or not. Doing `println` with the four substrings `"a"`, `"b"`, `"c"`, `"d"` produces exactly the same result as `println` the single `"a\nb\nc\nd"` string. The behavior indeed didn’t change between these Java versions, but in that `.split("\\\\n")` never worked, as the string literal evaluates to the string `\\n`, which is the regex pattern for “literal `\ `, followed by `n`”… – Holger Nov 20 '17 at 11:19
  • 1
    @Holger Thanks for the correction - [this](https://ideone.com/IAyTB9) corrected version should demonstrate it sufficiently. I wasn't sure why `\\\\n` seemed to work, that explains it. – hnefatl Nov 20 '17 at 11:37

0 Answers0