diff --git a/core-java-modules/core-java-string-operations-3/pom.xml b/core-java-modules/core-java-string-operations-3/pom.xml
index aa9fe38cca..00b37d2899 100644
--- a/core-java-modules/core-java-string-operations-3/pom.xml
+++ b/core-java-modules/core-java-string-operations-3/pom.xml
@@ -5,6 +5,7 @@
4.0.0
core-java-string-operations-3
0.1.0-SNAPSHOT
+
core-java-string-operations-3
jar
@@ -44,7 +45,22 @@
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ ${maven.compiler.target}
+
+
+
+
+
+ 11
+ 11
3.6.1
3.6.3
6.1.1
diff --git a/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/splitstringbynewline/SplitStringByNewLineUnitTest.java b/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/splitstringbynewline/SplitStringByNewLineUnitTest.java
index 9afba62947..2e6613b0be 100644
--- a/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/splitstringbynewline/SplitStringByNewLineUnitTest.java
+++ b/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/splitstringbynewline/SplitStringByNewLineUnitTest.java
@@ -1,9 +1,13 @@
package com.baeldung.splitstringbynewline;
import org.junit.Test;
+
+import java.util.regex.Pattern;
+
import static org.assertj.core.api.Assertions.assertThat;
public class SplitStringByNewLineUnitTest {
+
@Test
public void givenString_whenSplitByNewLineUsingSystemLineSeparator_thenReturnsArray() {
assertThat("Line1\nLine2\nLine3".split(System.lineSeparator())).containsExactly("Line1", "Line2", "Line3");
@@ -26,4 +30,20 @@ public class SplitStringByNewLineUnitTest {
assertThat("Line1\r\nLine2\r\nLine3".split("\\R")).containsExactly("Line1", "Line2", "Line3");
}
+
+ @Test
+ public void givenString_whenSplitByNewLineUsingJava8PatternClass_thenReturnsStream() {
+ Pattern pattern = Pattern.compile("\\R");
+
+ assertThat(pattern.splitAsStream("Line1\nLine2\nLine3")).containsExactly("Line1", "Line2", "Line3");
+
+ assertThat(pattern.splitAsStream("Line1\rLine2\rLine3")).containsExactly("Line1", "Line2", "Line3");
+
+ assertThat(pattern.splitAsStream("Line1\r\nLine2\r\nLine3")).containsExactly("Line1", "Line2", "Line3");
+ }
+
+ @Test
+ public void givenString_whenSplitByNewLineUsingJava11Lines_thenReturnsStream() {
+ assertThat("Line1\nLine2\rLine3\r\nLine4".lines()).containsExactly("Line1", "Line2", "Line3", "Line4");
+ }
}
diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml
index b801d44a08..4b80e7f0ed 100644
--- a/core-java-modules/pom.xml
+++ b/core-java-modules/pom.xml
@@ -111,7 +111,6 @@
core-java-string-conversions-2
core-java-string-operations
core-java-string-operations-2
- core-java-string-operations-3
core-java-sun
core-java-regex
pre-jpms
diff --git a/pom.xml b/pom.xml
index 686db65e8f..ccf9f86a55 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1293,6 +1293,7 @@
core-java-modules/core-java-datetime-string
core-java-modules/core-java-jpms
core-java-modules/core-java-os
+ core-java-modules/core-java-string-operations-3
core-java-modules/core-java-time-measurements
core-java-modules/multimodulemavenproject
@@ -1338,6 +1339,7 @@
core-java-modules/core-java-datetime-string
core-java-modules/core-java-jpms
core-java-modules/core-java-os
+ core-java-modules/core-java-string-operations-3
core-java-modules/core-java-time-measurements
core-java-modules/multimodulemavenproject
core-java-modules/core-java-strings