Question: Repeat Exercise R15.10 , using the removeIf method. (Read the description in the API of the Collection interface.) Use a lambda expression (see Special
Repeat Exercise •• R15.10 , using the removeIf method. (Read the description in the API of the Collection interface.) Use a lambda expression (see Special Topic 10.4).
Data from exercise R15.10 You are given a linked list of strings. How do you remove all elements with length less than or equal to three?
Data from special topic 10.4



Special Topic 10.4 Lambda Expressions In the preceding section, you saw how to use interfaces for specifying variations in behavior. The average method needs to measure each object, and it does so by calling the measure method of the supplied Measurer object. Unfortunately, the caller of the average method has to do a fair amount of work; namely, to define a class that implements the Measurer interface and to construct an object of that class. There is a convenient shortcut for these steps, provided that the interface has a single abstract method. Such an interface is called a functional interface because its purpose is to define a single function. The Measurer interface is an example of a functional interface. To specify that single function, you can use a lambda expression, an expression that defines the parameters and return value of a method in a compact notation. Here is an example: (Object obj) ((BankAccount) obj).getBalance() This expression defines a function that, given an object, casts it to a BankAccount and returns the balance.
Step by Step Solution
3.25 Rating (157 Votes )
There are 3 Steps involved in it
To solve exercise R1510 using the removeIf method with a lambda expression you need to apply these c... View full answer
Get step-by-step solutions from verified subject matter experts
