1Z0-809 · Question #234
7. BiPredicate<String, String> bp = (String s1, String s2) -> s1.contains("SG") && 8. s2.contains("Java"); 9. BiFunction<String, String, Integer> bf = (String s1, String s2) -> { 10. int fee = 0…
The correct answer is B. 100. Option B is correct because both conditions in the BiPredicate evaluate to true: "D101SG" contains "SG" and "Java Programming" contains "Java", so bp.test(s1, s2) returns true, causing fee to be set to 100, which is then returned and printed. Why the distractors are wrong…
Question
- BiPredicate<String, String> bp = (String s1, String s2) -> s1.contains("SG") &&
- s2.contains("Java");
- BiFunction<String, String, Integer> bf = (String s1, String s2) -> {
- int fee = 0;
- if (bp.test(s1, s2)) {
- fee = 100;
- }
- return fee;
- };
- int res1 = bf.apply("D101SG", "Java Programming");
- System.out.println(res1);
Options
- AA compilation error occurs at line 7.
- B100
- CA compilation error occurs at line 8.
- DA compilation error occurs at line 15.
How the community answered
(22 responses)- A9% (2)
- B73% (16)
- C14% (3)
- D5% (1)
Explanation
Option B is correct because both conditions in the BiPredicate evaluate to true: "D101SG" contains "SG" and "Java Programming" contains "Java", so bp.test(s1, s2) returns true, causing fee to be set to 100, which is then returned and printed.
Why the distractors are wrong: Lines 7 and 8 together form one valid lambda expression - line 8 is simply the continuation of the && condition started on line 7, so options A and C are wrong. Line 15 returns int fee, which is auto-boxed to Integer to satisfy BiFunction<String, String, Integer>, so option D is wrong too.
Memory tip: Remember the two key functional interface methods - BiPredicate uses .test() (returns boolean) and BiFunction uses .apply() (returns a value). When you see one nested inside the other, trace the data flow: evaluate the predicate first, then see how the function uses that result.
Community Discussion
No community discussion yet for this question.