Question: Consider the following code segment. ArrayList fruit = new ArrayList (); fruit.add(banana); fruit.add(apple); fruit.add(orange); fruit.add(fruit.remove(1)); fruit.set(1, fruit.remove(2)); System.out.println(fruit); What is printed as a result of

Consider the following code segment.

ArrayList fruit = new ArrayList(); fruit.add("banana"); fruit.add("apple"); fruit.add("orange"); fruit.add(fruit.remove(1)); fruit.set(1, fruit.remove(2)); System.out.println(fruit);

What is printed as a result of executing the code segment?

[banana, orange, orange, apple]

[orange, orange]

[banana, orange, apple]

[banana, apple, orange]

[banana, apple]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!