What are the common methods of Stream in java8
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