Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common methods of Stream in java8

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the common methods of Stream in java8, which have a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to know about it.

Stream commonly used methods to create Stream

Convert existing data structures to Stream

Stream s = Stream.of (1,2,3,4,5); Stream s = Arrays.stream (arr); Stream s = aList.stream ()

Through the Stream.generate () method:

/ / this method usually represents the infinite sequence Stream s = Stream.generate (SuppLier s); / / creates Streamclass NatualSupplier implements Supplier {BigInteger next = BigInteger.ZERO; @ Override public BigInteger get () {next = next.add (BigInteger.ONE); return next;}} of all natural numbers.

Return by other methods

Stream lines = Files.lines (Path.get (filename))... map method

Map an operation to each element of Stream to complete the conversion from one Stream to another Stream

The object the map method accepts is the Function interface, which is a functional interface:

Stream map (Function

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 292

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report