CJCoding With Joseph
15free / daySign inCreate account

The generic interface Checker<T> has one method, test, that answers yes or no about a value. Write a generic method that uses any checker to pick items out of a list. The tests pass in different rules, so your method must not know what the rule is.

Requirements: 1. Inside Filter, write a public static generic method named keep with one type parameter T. It takes an ArrayList<T> named items and a Checker<T> named rule, and it returns an ArrayList<T>. 2. The returned list is a NEW list. It holds, in their original order, only the items for which rule.test(item) is true. 3. Do not change the list that was passed in. 4. Do not change the Checker interface.

Do NOT write a main method.

Expected output

[11, 15, 20]
[4, 11, 8, 15, 20]
[planet, galaxy]

= newline. The output ends with a newline, so print one after the last line.

Hints4 available
Topics
GenericsMethods
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your output

Run your code to see the output here...

Test cases

Run your code to see test case results.