D: Predicate function = s -> s.contains("N"); not correct syntax
raw type Predicate class is considering parameter "s" as a type of Object
so there is an exception
MyClass.java:4: error: cannot find symbol
Predicate function = s -> s.contains("N");
should be
Predicate<String> function = s -> s.contains("N");
D is Correct
A List of String objects representing states is created and assigned to the states variable.
A Predicate<String> functional interface is created using a lambda expression and assigned to the function variable. The lambda expression checks if a given String contains the character "N".The removeIf() method is called on the states list, passing in the function variable as an argument. This method removes all elements from the list that satisfy the given predicate.
So, at the end of the program, all elements in the states list that contain the character "N" will be removed.
upvoted 1 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
ASPushkin
2 months, 3 weeks agod7bb0b2
1 year agoOmnisumem
1 year, 3 months agoStavok
1 year, 5 months ago