exam questions

Exam 1z0-819 All Questions

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

Exam 1z0-819 topic 1 question 55 discussion

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

Given:



Which statement on line 1 enables this code to compile?

  • A. Consumer function = (String f) -> (System.out.println(f);};
  • B. Supplier function = () -> fruits.get (0);
  • C. Predicate function = a -> a.equals("banana");
  • D. Function function = x -> x.substring(0,2);
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
ASPushkin
6 months ago
Selected Answer: A
answer: A List forEach default void forEach​(Consumer<? super T> action) There is syntax error with parentheses and generic type. it should be this way Consumer function = f->{System.out.println(f);}; or Consumer<String> function = f->{System.out.println(f);};
upvoted 1 times
...
Galen86
10 months, 3 weeks ago
In fact, the above answers are all wrong A seems correct, but the writing in lambda is wrong If rewritten as # Consumer function = s -> System.out.println(s); to compile normally
upvoted 1 times
...
d7bb0b2
1 year, 1 month ago
A is correct cause foreach accept consumer interface
upvoted 1 times
d7bb0b2
1 year ago
NOTICE: A is the correct but consumer is bad implement in the option because explicit paramater for lambda is (String f)->... and the compiler expect Object, the correct is : 1- Consumer x = x -> System.out.print(x) or: 2- Consumer<String> x = (String f) -> ..... o 3- Consumer<String> x= f -> sout...
upvoted 1 times
...
...
[Removed]
1 year, 5 months ago
Actually answer A is also incorrect. As Consumer is actually Consumer<Object> so it expects an Object rather than a String. It would've worked if it were: f -> System.out.println(f);
upvoted 1 times
...
tmuralimanohar
1 year, 7 months ago
Answer:A
upvoted 1 times
...
Stavok
1 year, 8 months ago
Selected Answer: A
forEach() accepts a Consumer, correct answer is A.
upvoted 1 times
...
Mukes877
1 year, 8 months ago
Selected Answer: A
forEach() accepts a Consumer, so correct answer is A.
upvoted 1 times
...
Ankit1010
1 year, 12 months ago
forEach() accepts a Consumer, so correct answer is A. Consumer function = f -> System.out.println(f);
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