OptionalLong stream() method in Java with examples Last Updated : 28 May, 2019 Comments Improve Suggest changes Like Article Like Report The stream() method help us to get Long value contain by OptionalLong as LongStream.If a value is present, method returns a sequential LongStream containing only that value, otherwise returns an empty LongStream. Syntax: public LongStream stream() Parameters: This method accepts nothing. Return value: This method returns the optional value as an LongStream. Below programs illustrate stream() method: Program 1: Java // Java program to demonstrate // OptionalLong.stream() method import java.util.OptionalLong; import java.util.stream.LongStream; public class GFG { public static void main(String[] args) { // create a OptionalLong OptionalLong opLong = OptionalLong.of(163252382159472124L); // get value as stream LongStream out = opLong.stream(); // print value System.out.print("Value: "); out.forEach(System.out::print); } } Output: Program 2: Java // Java program to demonstrate // OptionalLong.stream() method import java.util.OptionalLong; import java.util.stream.LongStream; public class GFG { public static void main(String[] args) { // create a empty OptionalLong OptionalLong opLong = OptionalLong.empty(); // get value as stream LongStream out = opLong.stream(); // print value System.out.print("length of Long Stream: " + out.count()); } } Output: References: https://docs.oracle.com/javase/10/docs/api/java/util/OptionalLong.html#empty() Comment More infoAdvertise with us Next Article OptionalLong stream() method in Java with examples A AmanSingh2210 Follow Improve Article Tags : Java Java - util package Java-Functions Java-OptionalLong Practice Tags : Java Similar Reads 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 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 OptionalDouble stream() method in Java with examples The stream() method help us to get double value contain by OptionalDouble as DoubleStream.If a value is present, method returns a sequential DoubleStream containing only that value, otherwise returns an empty DoubleStream. Syntax: public DoubleStream stream() Parameters: This method accepts nothing. 1 min read Stream min() method in Java with Examples Stream.min() returns the minimum element of the stream based on the provided Comparator. A Comparator is a comparison function, which imposes a total ordering on some collection of objects. min() is a terminal operation which combines stream elements and returns a summary result. So, min() is a spec 3 min read PrintStream println() method in Java with Examples The println() method of PrintStream Class in Java is used to break the line in the stream. This method do not accepts any parameter or return any value. Syntax: public void println() Parameters: This method do not accepts any parameter. Return : This method do not returns any value. Below methods il 2 min read Stream peek() Method in Java with Examples In Java, Stream provides an powerful alternative to process data where here we will be discussing one of the very frequently used methods named peek() which being a consumer action basically returns a stream consisting of the elements of this stream, additionally performing the provided action on ea 2 min read Stream skip() method in Java with examples Prerequisite : Streams in java The skip(long N) is a method of java.util.stream.Stream object. This method takes one long (N) as an argument and returns a stream after removing first N elements. skip() can be quite expensive on ordered parallel pipelines, if the value of N is large, because skip(N) 3 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 Stream ofNullable(T) method in Java with examples The ofNullable(T) method returns a sequential Stream containing a single element if this stream is non-null otherwise method returns an empty Stream. It helps to handle the null stream and NullPointerException. Syntax: static <T> Stream<T> ofNullable(T t) Parameters: This method accepts 2 min read PrintStream println(Object) method in Java with Examples The println(Object) method of PrintStream Class in Java is used to print the specified Object on the stream and then break the line. This Object is taken as a parameter. Syntax: public void println(Object object) Parameters: This method accepts a mandatory parameter object which is the Object to be 2 min read Like