Stream empty() in Java with Examples Last Updated : 06 Dec, 2018 Comments Improve Suggest changes Like Article Like Report Stream empty() creates an empty sequential Stream. Syntax : static <T> Stream<T> empty() Parameters : T : The type of stream elements. Stream : A sequence of objects that supports various methods which can be pipelined to produce the desired result. Return Value : Stream empty() returns an empty sequential stream. Note : An empty stream might be useful to avoid null pointer exceptions while callings methods with stream parameters. Example : Java // Java code for Stream empty() import java.util.*; import java.util.stream.Stream; class GFG { // Driver code public static void main(String[] args) { // Creating an empty Stream Stream<String> stream = Stream.empty(); // Displaying elements in Stream stream.forEach(System.out::println); } } Output : No Output Comment More infoAdvertise with us Next Article Stream empty() in Java with Examples S Sahil_Bansall Follow Improve Article Tags : Java Practice Tags : Java Similar Reads Stream anyMatch() in Java with examples Stream anyMatch(Predicate predicate) returns whether any elements of this stream match the provided predicate. It may not evaluate the predicate on all elements if not necessary for determining the result. This is a short-circuiting terminal operation. A terminal operation is short-circuiting if, wh 2 min read Stream builder() in Java with Examples Stream builder() returns a builder for a Stream. Syntax : static <T> Stream.Builder<T> builder() where, T is the type of elements. Return Value : A stream builder. Example 1 : Java // Java code for Stream builder() import java.util.*; import java.util.stream.Stream; class GFG { // Driver 2 min read LongStream count() in Java with examples LongStream count() returns the count of elements in the stream. LongStream count() is present in java.util.stream.LongStream Syntax : long count() Example 1 : Count the elements in LongStream. Java // Java code for LongStream count() // to count the number of elements in // given stream import java. 2 min read IntStream empty() in Java with examples IntStream empty() is a method in java.util.stream.IntStream. This method returns an empty sequential IntStream. Syntax : static <T> Stream<T> empty() Where, T is the type of stream elements, and the function returns an empty sequential stream. Example 1 : Creating empty IntStream. Java / 1 min read BitSet stream() Method in Java with Examples The stream() method of Java BitSet class is used to return a stream of indices for every bit contained in the BitSet. The indices are returned in increasing order. The size of the stream is the number of bits in the set state of the BitSet, which is equal to the value returned by the cardinality() m 2 min read Stream filter() in Java with examples Stream filter(Predicate predicate) returns a stream consisting of the elements of this stream that match the given predicate. This is an intermediate operation. These operations are always lazy i.e, executing an intermediate operation such as filter() does not actually perform any filtering, but ins 3 min read Stream.of(T t) in Java with examples Stream of(T t) returns a sequential Stream containing a single element i.e, a singleton sequential stream. A sequential stream work just like for-loop using a single core. On the other hand, a Parallel stream divide the provided task into many and run them in different threads, utilizing multiple co 2 min read Stream count() method in Java with examples long count() returns the count of elements in the stream. This is a special case of a reduction (A reduction operation takes a sequence of input elements and combines them into a single summary result by repeated application of a combining operation). This is a terminal operation i.e, it may travers 2 min read Stream toArray() in Java with Examples Stream toArray() returns an array containing the elements of this stream. It is a terminal operation i.e, it may traverse the stream to produce a result or a side-effect. After the terminal operation is performed, the stream pipeline is considered consumed, and can no longer be used. Syntax : Object 2 min read Stream flatMap() in Java with examples Stream flatMap(Function mapper) returns a stream consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element. Stream flatMap(Function mapper) is an intermediate operation. These operations 5 min read Like