From the course: Advanced Java Programming
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Understanding streams in Java - Java Tutorial
From the course: Advanced Java Programming
Understanding streams in Java
- [Instructor] Streams provide a clean and simple way to iterate over a collection in Java. Instead of using a forEach loop, streams allow functional programming techniques to be used. These streams are not to be confused with input and output streams which are something completely different. For example, this is a forEach loop, which iterates over a collection of books. If the author of the book's name begins with the letter J, then the two-string method of book is called and printed to the terminal. When I use a forEach loop like this in Java, it uses something called external iteration. What actually happens under the hood is an iterator object is created. The iterator object controls the iteration process. For each item in the collection, it checks if the book's author begins with J. If it does, it goes to the print statements. And if not, then it does nothing. Then it checks if there is a next item in the collection. If there is, then it calls the next method to move to the next…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.