Question: P9.17 Declare an interface Filter as follows: public interface Filter { boolean accept(Object x); } Write a method: public static ArrayList collectAll(ArrayList objects, Filter f)
P9.17
Declare an interface Filter as follows:
public interface Filter { boolean accept(Object x); }
Write a method: public static ArrayList collectAll(ArrayList objects, Filter f) that returns all objects in the objects list that are accepted by the given filter.
Provide a class ShortWordFilter whose filter method accepts all strings of length < 5.
Then write a program that asks the user for input and output textfile names, reads all words from inputfile, puts them into an ArrayList, calls collectAll, and prints a list of the short words to the output file.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
