课程: Java: Advanced Concepts for High-Performance Development

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Understanding streams in Java

Understanding streams in Java

- [Instructor] Streams provide a powerful way to work with sequences of elements in Java. They have a slightly confusing name and that they sound similar to input and output streams, but actually, they're completely different things. The most common way to create a stream using the Streams API is from an existing collection. So for example, if I have a list of integers called numbers, I could turn that into a stream by doing numbers.stream to call the stream method, and that would give me back a stream. There are two different types of operation you can perform on a stream, intermediate and terminal. Intermediate operations always return another stream so you can chain them together. Terminal operations return void or any other type that's not a stream, so you can't call anything else once you've called a terminal operation. One example of an intermediate method is sorted. So if I call the sorted method on my stream of…

内容