0% found this document useful (0 votes)
4 views

Java Stream Operators

The document outlines the different types of operators in Java Streams, categorized into source, intermediate, terminal, and short-circuiting operators. Source operators create streams from various data sources, intermediate operators transform or filter data, terminal operators trigger execution and produce results, and short-circuiting operators enhance performance by stopping execution early based on conditions. Each category includes specific methods and their functionalities.

Uploaded by

dinesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Java Stream Operators

The document outlines the different types of operators in Java Streams, categorized into source, intermediate, terminal, and short-circuiting operators. Source operators create streams from various data sources, intermediate operators transform or filter data, terminal operators trigger execution and produce results, and short-circuiting operators enhance performance by stopping execution early based on conditions. Each category includes specific methods and their functionalities.

Uploaded by

dinesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Operators in Java Streams

1️. Source Operators


Create a stream from a collection, array, or I/O source.

• stream() – Converts a collection into a sequential stream.

• parallelStream() – Creates a parallel stream for multi-threading.

• Stream.of() – Generates a stream from given values.

• Arrays.stream() – Converts an array into a stream.

• IntStream.range() – Creates a stream of numbers within a range.

• BufferedReader.lines() – Converts lines of a file into a stream.

2️. Intermediate Operators


Transform or filter data without executing immediately (lazy evaluation).

• filter() – Selects elements that match a given condition.

• map() – Transforms each element using a function.

• flatMap() – Flattens nested structures into a single stream.

• distinct() – Removes duplicate elements from the stream.

• sorted() – Sorts elements in natural or custom order.

• limit(n) – Restricts the stream to the first n elements.

• skip(n) – Skips the first n elements in the stream.

• peek() – Used for debugging without modifying elements.

3️. Terminal Operators


Trigger execution and produce a final result, consuming the stream.

• collect() – Converts a stream into a List, Set, or Map.

• forEach() – Performs an action for each element.

• count() – Returns the number of elements in the stream.


• findFirst() – Retrieves the first element of the stream.

• findAny() – Retrieves any element from the stream.

• reduce() – Aggregates elements into a single result.

• toArray() – Converts stream elements into an array.

4️. Short-Circuiting Operators


Stop execution early when a condition is met for better performance.

• anyMatch() – Returns true if any element matches a condition.

• allMatch() – Returns true if all elements match a condition.

• noneMatch() – Returns true if no elements match a condition.

• limit(n) – Stops processing after selecting n elements.

• findFirst() – Retrieves the first element and stops further operations.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy