src/java.base/share/classes/java/lang/String.java
changeset 50215 2fb27c352cae
parent 50175 589ed2770141
child 50237 ec52b4d094c0
--- a/src/java.base/share/classes/java/lang/String.java	Tue May 22 12:26:17 2018 +0200
+++ b/src/java.base/share/classes/java/lang/String.java	Tue May 22 12:04:05 2018 -0300
@@ -41,6 +41,7 @@
 import java.util.regex.Pattern;
 import java.util.regex.PatternSyntaxException;
 import java.util.stream.IntStream;
+import java.util.stream.Stream;
 import java.util.stream.StreamSupport;
 import jdk.internal.HotSpotIntrinsicCandidate;
 import jdk.internal.vm.annotation.Stable;
@@ -2754,6 +2755,39 @@
     }
 
     /**
+     * Returns a stream of substrings extracted from this string
+     * partitioned by line terminators.
+     * <p>
+     * Line terminators recognized are line feed
+     * {@code "\n"} ({@code U+000A}),
+     * carriage return
+     * {@code "\r"} ({@code U+000D})
+     * and a carriage return followed immediately by a line feed
+     * {@code "\r\n"} ({@code U+000D U+000A}).
+     * <p>
+     * The stream returned by this method contains each line of
+     * this string that is terminated by a line terminator except that
+     * the last line can either be terminated by a line terminator or the
+     * end of the string.
+     * The lines in the stream are in the order in which
+     * they occur in this string and do not include the line terminators
+     * partitioning the lines.
+     *
+     * @implNote This method provides better performance than
+     *           split("\R") by supplying elements lazily and
+     *           by faster search of new line terminators.
+     *
+     * @return  the stream of strings extracted from this string
+     *          partitioned by line terminators
+     *
+     * @since 11
+     */
+    public Stream<String> lines() {
+        return isLatin1() ? StringLatin1.lines(value)
+                          : StringUTF16.lines(value);
+    }
+
+    /**
      * This object (which is already a string!) is itself returned.
      *
      * @return  the string itself.