public class Test {
public static void checkAge(List<Person> personList, Predicate<Person> pearsonPredicate){
for(Person p : personList){
if(pearsonPredicate.test(p)){
System.out.println(p.name + " ");
}
}
}
public static void main(String[] args){
List<Person> personList = Arrays.asList(new Person("Hank", 45),
new Person("Charlie", 40),
new Person("Smith", 38)
);
checkAge(personList, p -> p.getAge() > 40);
}
}
Answer is C.
Answer is C.
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
public class TestPredicate {
public static void checkAge(List<Person> list, Predicate <Person> predicate ) {
for (Person p:list) {
if (predicate.test(p)) {System.out.println(p.name + " ");}
}
}
public static void main(String[] args) {
List<Person> iList=Arrays.asList(new Person("Hank", 45),
new Person("Charlie",40),
new Person("Smith", 38));
checkAge(iList, p -> p.getAge() > 40);
}
}
Output: Hank
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.
Skytrix
1 month, 3 weeks agoyanoolthecool
1 week, 6 days agoVicky_65
8 months, 1 week agoAnkit1010
10 months, 1 week agoodzio33
11 months agoUAK94
1 year, 2 months ago