Use of the "Java" stream

Source: Internet
Author: User

First of all, to recommend a good place: http://ifeve.com/stream/can learn a bit

Next, we're going to delete some elements of the array today, thinking about the JDK8 stream that I used before.

1.Array Convert to stream and filter

"There's a pit: There are two ways to convert an array to stream

1.stream.of (Array)

2.arrays.stream (Array)

Difference: Both support reference data types, but if it is the basic data type, choose the second one, so it is appropriate to use the second in proper period.

】

The code is as follows:

@org. Junit.test      Public void throws ioexception{        = "2.1.1&2.1.2&2.1.5&2.1.6&3.1.1&3.2.2&3.3.3&4.1.1& 4.1.2&4.1.4&5.1.2&7.1.2&7.2.1&7.3.1.1&7.3.3.1&7.3.4.3&7.3.5.2&7.3.6.2& 7.3.6.3 ". Split (" & ");        Stream<String> stream = arrays.stream (str);         = Stream.filter (S-s.contains ("2.1.") ) . ToArray ();          for (int i = 0; i < o1.length; i++) {            System.out.println (str[i].tostring ());        }    }

2.List Collection converted to stream

"Collection. Stream () can"

Use of the "Java" stream

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.