Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Oracle 1Z0-809 Exam - Topic 13 Question 87 Discussion

Actual exam question for Oracle's 1Z0-809 exam
Question #: 87
Topic #: 13
[All 1Z0-809 Questions]

Given the code fragment:

List str = Arrays.asList (''my'', ''pen'', ''is'', ''your', ''pen'');

Predicate test = s -> {

int i = 0;

boolean result = s.contains (''pen'');

System.out.print(i++) + '':'');

return result;

};

str.stream()

.filter(test)

.findFirst()

.ifPresent(System.out ::print);

What is the result?

Show Suggested Answer Hide Answer
Suggested Answer: A

Contribute your Thoughts:

0/2000 characters
Felix
3 months ago
I'm not sure about that output, seems odd.
upvoted 0 times
...
Kaitlyn
3 months ago
I think it's option B!
upvoted 0 times
...
Cecil
3 months ago
The code prints the index before finding "pen".
upvoted 0 times
...
Olive
3 months ago
Definitely not a compilation error, so E is out!
upvoted 0 times
...
Yoko
4 months ago
Wait, why is there an increment in the print statement?
upvoted 0 times
...
Tiara
4 months ago
I thought the print statement would just print the index, but now I'm wondering if it prints every time the predicate is checked.
upvoted 0 times
...
Viva
4 months ago
I feel like the answer might be B, but I’m confused about how many times the print statement executes.
upvoted 0 times
...
Chun
4 months ago
I remember a similar question where we had to count occurrences, but I can't recall if the print statement affects the filter.
upvoted 0 times
...
Nan
4 months ago
I think the output will show the index of each match, but I'm not sure if it starts from 0 or 1.
upvoted 0 times
...
Lashandra
5 months ago
Wait, I'm not sure about this. The Predicate is printing multiple index values, but the question asks for a single result. I'll need to think this through carefully.
upvoted 0 times
...
Cordelia
5 months ago
I'm pretty sure the answer is B. The Predicate is printing the index, but the stream operation is just finding the first match, which should be "pen".
upvoted 0 times
...
Stefania
5 months ago
Okay, I think I've got it. The Predicate is printing the index as a side effect, but the actual return value is whether the string contains "pen". So the result should be the first string that contains "pen".
upvoted 0 times
...
Elvera
5 months ago
Hmm, I'm a bit confused by the Predicate implementation. Why is it printing the index value instead of just checking for the "pen" string?
upvoted 0 times
...
Asha
5 months ago
This looks like a tricky one. I'll need to carefully read through the code and understand what's happening with the stream and the Predicate.
upvoted 0 times
...
Beckie
8 months ago
This is a trick question! The correct answer is obviously C) 0 : 0 : 0 : 0 : 0 : pen. Because who doesn't love a good infinite loop?
upvoted 0 times
...
King
8 months ago
D) 0 : 1 : 2 : 3 : 4 : - This can't be right. The question clearly states that the output should include 'pen', not just the counter values.
upvoted 0 times
...
France
8 months ago
B) 0 : 1 : pen - Hmm, I'm not sure about this one. The counter is incremented for each match, so I think the correct answer is A.
upvoted 0 times
Mignon
7 months ago
B) 0 : 1 : pen - I'm not sure either, but I think you might be onto something with option A.
upvoted 0 times
...
Kati
7 months ago
A) 0 : 0 : pen - I think you're right, the counter is only incremented once for each match.
upvoted 0 times
...
...
Linwood
8 months ago
E) A compilation error occurs. - What? No way, this code looks perfectly fine to me. I think you need to double-check your understanding of Java streams.
upvoted 0 times
Willard
7 months ago
User 3: B) 0 : 1 : pen
upvoted 0 times
...
Margurite
7 months ago
User 2: A) 0 : 0 : pen
upvoted 0 times
...
Louis
8 months ago
User 1: E) A compilation error occurs. - What? No way, this code looks perfectly fine to me. I think you need to double-check your understanding of Java streams.
upvoted 0 times
...
...
Sheridan
9 months ago
I'm not sure, but I think the answer might be E) A compilation error occurs because of a syntax error in the code
upvoted 0 times
...
Carey
9 months ago
I agree with Reyes, the code prints 0 : 1 : pen because of the way the Predicate is implemented
upvoted 0 times
...
Reyes
9 months ago
I think the answer is B) 0 : 1 : pen because the code fragment increments i each time it prints
upvoted 0 times
...
Sheridan
9 months ago
A) 0 : 0 : pen - This seems like the correct answer. The predicate checks if the string contains 'pen' and prints the value of the counter, which starts at 0 and increments for each match.
upvoted 0 times
Joanna
8 months ago
D) 0 : 1 : 2 : 3 : 4 :
upvoted 0 times
...
Buck
8 months ago
C) 0 : 0 : 0 : 0 : 0 : pen
upvoted 0 times
...
Ammie
8 months ago
B) 0 : 1 : pen
upvoted 0 times
...
Louvenia
9 months ago
A) 0 : 0 : pen
upvoted 0 times
...
...

Save Cancel