exam questions

Exam 1z0-809 All Questions

View all questions & answers for the 1z0-809 exam

Exam 1z0-809 topic 1 question 41 discussion

Actual exam question from Oracle's 1z0-809
Question #: 41
Topic #: 1
[All 1z0-809 Questions]

Given the code fragment:
List<String> str = Arrays.asList ("my", "pen", "is", "your', "pen");
Predicate<String> 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?

  • A. 0 : 0 : pen
  • B. 0 : 1 : pen
  • C. 0 : 0 : 0 : 0 : 0 : pen
  • D. 0 : 1 : 2 : 3 : 4 :
  • E. A compilation error occurs.
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Destroyer
Highly Voted 4 years, 7 months ago
Answer is A
upvoted 9 times
...
Saurabhag
Highly Voted 4 years ago
Correct Answer is A(tested)
upvoted 5 times
...
asdfjhfgjuaDCV
Most Recent 4 months, 3 weeks ago
The correct answer is A.List<String> str = Arrays.asList ("my", "pen", "is", "your', "pen"); Check this once if it is correct then A
upvoted 1 times
...
steefaand
5 months, 3 weeks ago
Selected Answer: A
Assuming that "your' is typo (using ' instead of ") answer is A, since variable i is created every time predicate is run and its value is always 0 because of post increment. And since value is found on 2nd iteration 0 is printed twice.
upvoted 1 times
...
iSnover
6 months, 1 week ago
Selected Answer: D
The answer is D, because in the list "str" ​​the fourth String is instantiated as "your' without double quotes as it should be. Correcting the error, the correct answer is A, pay attention to the test as the question may come with the model with compilation error or may come with the result "0 : 0 : pen"
upvoted 1 times
...
r1muka5
1 year, 4 months ago
Answer A
upvoted 1 times
...
wheredajuice
2 years, 4 months ago
It's A because of findFirst(), it only does the test for the first two elements, finds "pen" in the second position and terminates. Also notice "int i" is a local variable in the lambda, it always prints 0.
upvoted 2 times
...
WilsonKKerll
2 years, 4 months ago
Answer is A. Because Predicate test() is one test with any element in List.
upvoted 1 times
...
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.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago