Operations Types In Java Stream API

There are mainly 3 types of operations.

  1. Intermediate operations
  2. The intermediate operation returns another stream as a result, they can be chained together to form a pipeline of operations.
    - filter()
    Filter the elements based on a specified condition. details...
    - map()
    Transforms each of the elements in a stream to another value. details...
    - sorted()
    Sorts the elements of a stream. details...
  3. Terminal operations
  4. The terminal operation means after calling this method on Stream, you cannot call any other method on Stream.
    - forEach()
    It iterates all the elements in a stream.  details...
    - collect()
    The stream.collect() method accumulate elements of any Stream into a Collection, it is a part of stream terminal operation. The Collector class provides different methods like toList(), toSet(), toMap(), and toConcurrentMap() to collect the result of Stream into List, Set, Map, and ConcurrentMap in Java. It accepts a Collector in arguments to accumulate elements of Stream into a specified Collection such as stream().collect(Collectors.toList()).  details...
    - anyMatch() and allMatch()
    The anyMatch operation checks if any element of a stream matches a given condition, while the allMatch operation checks if all elements   satisfy the given condition.  details...
    - count()
    The count operation returns the number of elements in a stream as a long value details...
    - reduce()
    It is used to reduce the elements of a stream to a single value. details...
  5. Short-circuit operations
  6. - findFirst()
    The findFirst() method finds the first element in a Stream. we use this method when we specifically want the first element from a   sequence. details...
    - anyMatch()
    It checks the stream if it satisfies the given condition. details...