java Stream flow essays

Stream is a new feature of jdk8, JDK8 joined java.util.stream package implements a set of operations flow, flow operation comprises filtering, sorting, mapping set of functions. The operability of the stream, and can be divided into a serial stream of parallel streams. Depending on the result of the operation is returned, the operation flow is divided into a final operation and intermediate operation. Greatly facilitate the operation for our collection.

  • Final Action: returns the result of a particular type.
  • Intermediate: Return flow itself

What is the flow: Stream not set elements, nor is the data structure, which is equivalent to an advanced version of Iterator, which can not be repeated traversal of data, like water, flows through the gone forever. It is ordinary Iterator different is that it can traverse parallel, serial common Iterator can only be executed in a thread.

Intermediate operations:
filter (): for the filter elements
sorted (): sort the elements
map (): elemental mapping
distinct (): removing duplicate elements
final operation:
forEach (): through each element.
reduce (): The combined element Stream. For example, string concatenation, sum value, min, max, average are special reduce.
collect (): Returns a new collection.
min (): minimum is found.
max (): find the maximum value.

Guess you like

Origin www.cnblogs.com/Fsight/p/12452649.html