exam questions

Exam 1z0-808 All Questions

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

Exam 1z0-808 topic 1 question 127 discussion

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

Given the code fragment:

What is the result?

  • A. [green, red, yellow, cyan]
  • B. [green, blue, yellow, cyan]
  • C. [green, red, cyan, yellow]
  • D. An IndexOutOfBoundsException is thrown at runtime.
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
Priyamed
5 months, 3 weeks ago
Answer is B, tested it
upvoted 1 times
...
akbiyik
2 years, 2 months ago
Selected Answer: B
Answer is B void add(int index, E element); IndexOutOfBoundsException – if the index is out of range (index < 0 || index >= size())
upvoted 1 times
...
carloswork
2 years, 3 months ago
Selected Answer: B
Answer is B. Here's an example: public static void main(String[] args) { List <String> colors = new ArrayList(); colors.add("Green"); colors.add("Blue"); colors.add("Red"); colors.add("Yelow"); colors.remove(2); colors.add(3,"Cyan"); System.out.println(colors); }
upvoted 1 times
...
iSnover
2 years, 3 months ago
Selected Answer: B
The correct answer is the letter B, in line 18 the element that is in index 2 of the list is removed, remembering that Java indexes from 0, the element that will be removed is "red" and "yellow" which was in position 3 of the list after removal goes to position 2, in line 19 the element "cyan" is added at position 3 which is empty. and when printing on line 20, it returns [green, blue, yellow, cyan] which is the answer for the letter B. There is no way to throw the exception "IndexOutOfBounds" because in the line that the exclusion is made, it was made in a position that it had in the list and addition as well, since it was an empty position and the list was not set a fixed size for it.
upvoted 1 times
...
alex_au
2 years, 4 months ago
Result should be B, from the documentation the add(int index, object element) method will only raise IndexOutOfBoundsException if the index is out of range (index < 0 || index > size()). https://docs.oracle.com/javase/8/docs/api/java/util/List.html#add-int-E-
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