exam questions

Exam 1z0-808 All Questions

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

Exam 1z0-808 topic 1 question 196 discussion

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

Given the code fragment:

What is the result?

  • A. [JavaForum, ExpertForum]
  • B. [JavaGroup, ExpertGroup]
  • C. [JavaForumGroup, ExpertForumGroup]
  • D. [JavaGroup, TechGroup ExpertGroup]
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

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
akbiyik
1 year, 1 month ago
The correct answer is B
upvoted 2 times
...
iSnover
1 year, 3 months ago
Selected Answer: B
The answer is the letter B, the "forEach" method does the concatenation and the "replaceAll" method replaces the last concatenation with the argument you pass. I tested the code: public static void main (String[] args) { List<String> arrayList = new ArrayList<>(); arrayList.add("Tech"); arrayList.add("Expert"); arrayList.set(0, "Java"); arrayList.forEach(a -> a.concat("Forum")); arrayList.replaceAll(s -> s.concat("Group")); System.out.println(arrayList); }
upvoted 3 times
jackymak
7 months, 1 week ago
If you comment the foreach line, you can also get JavaGroup and ExpertGroup. I think replaceAll can make concatenation valid but not foreach: public static void main(String[] args) { List<String> arrayList = new ArrayList<>(); arrayList.add("Tech"); arrayList.add("Expert"); arrayList.set(0, "Java"); // arrayList.forEach(a -> a.concat("Forum")); arrayList.replaceAll(s -> s.concat("Group")); System.out.println(arrayList); } //output: [JavaGroup, ExpertGroup]
upvoted 1 times
DriftKing
4 months ago
forEach iterates over each element in the arrayList, then Concat returns a new string. It does not change the original string in the arrayList. Replaceall will replace the original string in the arrayList.
upvoted 3 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