Pattern splitAsStream() Method in Java with Examples Last Updated : 06 Mar, 2019 Comments Improve Suggest changes Like Article Like Report splitAsStream() method of a Pattern class used to return a stream of String from the given input sequence passed as parameter around matches of this pattern.this method is the same as the method split except that what we get back is not an array of String objects but a stream. If this pattern does not match any subsequence of the input then the resulting stream has just one element, namely the input sequence in string form. Syntax: public Stream<String> splitAsStream(CharSequence input) Parameters: This method accepts a single parameter CharSequence which represents character sequence to be split. Return value: This method returns a stream of strings computed by splitting the input around matches of this pattern. Below programs illustrate the splitAsStream() method: Program 1: Java // Java program to demonstrate // Pattern.splitAsStream(CharSequence input) method import java.util.regex.*; import java.util.stream.*; public class GFG { public static void main(String[] args) { // create a REGEX String String REGEX = "geeks"; // create the string // in which you want to search String actualString = "Welcome to geeks for geeks"; // create a Pattern using REGEX Pattern pattern = Pattern.compile(REGEX); // split the text Stream<String> stream = pattern .splitAsStream(actualString); // print array stream.forEach(System.out::println); } } Output: Welcome to for Program 2: Java // Java program to demonstrate // Pattern.splitAsStream(CharSequence input) method import java.util.regex.*; import java.util.stream.*; public class GFG { public static void main(String[] args) { // create a REGEX String String REGEX = "ee"; // create the string // in which you want to search String actualString = "aaeebbeecceeddee"; // create a Pattern using REGEX Pattern pattern = Pattern.compile(REGEX); // split the text Stream<String> stream = pattern .splitAsStream(actualString); // print array stream.forEach(System.out::println); } } Output: aa bb cc dd Reference: https://docs.oracle.com/javase/10/docs/api/java/util/regex/Pattern.html#splitAsStream(java.lang.CharSequence) Comment More infoAdvertise with us Next Article Pattern splitAsStream() Method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java - util package Java-Functions java-regular-expression Java-Pattern +1 More Practice Tags : Java Similar Reads OptionalInt stream() method in Java with examples The stream() method help us to get value contain by OptionalInt as IntStream. If a value is present, method returns a sequential IntStream containing only that value, otherwise returns an empty IntStream. Syntax: public IntStream stream() Parameters: This method accepts nothing. Return value: This m 1 min read Optional stream() method in Java with examples The stream() method of java.util.Optional class in Java is used to get the sequential stream of the only value present in this Optional instance. If there is no value present in this Optional instance, then this method returns returns an empty Stream. Syntax: public Stream<T> stream() Paramete 2 min read PrintStream flush() method in Java with Examples The flush() method of PrintStream Class in Java is used to flush the stream. By flushing the stream, it means to clear the stream of any element that may be or maybe not inside the stream. It neither accepts any parameter nor returns any value. Syntax: public void flush() Parameters: This method do 2 min read Stream noneMatch() Method in Java with Examples A stream is a sequence of objects that supports various methods which can be pipelined to produce the desired result. noneMatch() of Stream class returns whether no elements of this stream match the provided predicate. It may not evaluate the predicate on all elements if not necessary for determinin 3 min read PushbackInputStream read() method in Java with Examples The read() method of PushbackInputStream class in Java is of two types: The read() method of PushbackInputStream class in Java is used to read the next byte of data from the input stream. This method returns the read byte from the input stream in the form of an integer. Syntax: public int read() thr 4 min read Like