mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8200380: String::lines
Reviewed-by: sundar, sherman, rriggs, psandoz
This commit is contained in:
parent
c3cdecd32b
commit
60de3c902e
4 changed files with 327 additions and 0 deletions
|
@ -41,6 +41,7 @@ import java.util.regex.Matcher;
|
|||
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;
|
||||
|
@ -2753,6 +2754,39 @@ public final class String
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue