From the course: Advanced Java Programming

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Implementing streams in Java

Implementing streams in Java - Java Tutorial

From the course: Advanced Java Programming

Start my 1-month free trial

Implementing streams in Java

- [Instructor] In this example, I have a forEach loop which I can rewrite using a string. In the project, I have a class called Book. The constructor in the Book class takes two arguments, the author and the title of the book. The class also has getter methods for the author and the title and it overrides the toString method. This is so that when I call toString, it prints out to the author and the title of the book instead of the object's reference. Next, I have a class called Library. In this class, I have a method called populateLibrary. This method creates an ArrayList of books. And then it adds lots of new books to the ArrayList. Some of the books have the same author. Finally, it returns the ArrayList of books. This is the list I will use to demonstrate strings. So, in the Main method, I have created a new ArrayList of books and populate it using the populateLibrary method. I now have an ArrayList containing lots of books. Now I am going to use a string to print out all of the…

Contents