© Ralph Lecessi 2019
Ralph LecessiFunctional Interfaces in Javahttps://doi.org/10.1007/978-1-4842-4278-0_8

8. Use in Traversing Objects

Ralph Lecessi1 
(1)
Kendall Park, NJ, USA
 

The traversal of data structures has been simplified through the use of consumers which can be used to replace the while loops associated with iterators.

Section 8.1: Traversing Objects Using Iterators

Given the following Car class,
class Car
{
    private String make;
    private String model;
    public Car(String ma, String mo)
    {
        make = ma;
        model = mo;
    }
    @Override
    public String toString() {return make + " " + model; }
}
Listing 8-1

Car.java

a program can create a list of cars.
List<Car> cars = Arrays.asList(
    new Car("Nissan"   , "Sentra" ),
    new ...

Get Functional Interfaces in Java: Fundamentals and Examples now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.