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.
ArrayListfruit = 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
Get step-by-step solutions from verified subject matter experts
