Stream class of Java8

Source: Internet
Author: User

Stream is a tool that uses functional programming to perform complex operations on a collection class.

1.collect (ToList ())

Generate a list from the values in the Stream

List<string> collected = Stream.of ("A", "B", "C")                               

2.map

Converts a value in a stream to a new stream

List<string> collected = Stream.of ("A", "B", "Hello")                               , string.touppercase ())                               . Collect (ToList ());

3.filter

Qualifying values are preserved

list<string> beginningwithnumbers = Stream.of ("A", "1abc", "ABC1")                                          , IsDigit (Value.charat (0 ))                                           . Collect (ToList ());

4.flatmap

First flatten the input data and then map the values after the flat

5.max, Min

Track Shortesttrack = tracks.stream (                            ), track.getlength ())                            . get ();

Summarize:

? Internal iterations give more control to the collection class.

? Like Iterator, Stream is an internal iterative approach.

? Many common collection operations can be accomplished by combining LAMBDA expressions with the methods on the Stream.

Reference: "Java8 functional Programming"

Stream class of Java8

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.