Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the common methods of Stream in java8

Shulou Source: shulou.com Published: 2022-06-01 02:32:17 09月16日 Update

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

Tags: Methods elements interfaces types functions objects data articles results commonly used two actions consistency parameters sequences databases arrays conditions flow requests sorting Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Information macOS Redmi vpn