Menu
Question Index
...

What will be the output of the following program?

import java.util.*;
public class Copy {
    public static void main(String[] args) {
        List<String> list1 = new ArrayList<String>();
        list1.add("M");
        list1.add("E");
        List<String> list2 = list1;
        list1.add("R");
        list1.add("I");
        list1.add("T");
        System.out.format("%s", list1);
        System.out.format("%s", list2);
    }
}


[M, E, R, I, T]
[M, E, R, I, T][M, E]
[M, E, R, I, T][R, I, T]
[M, E, R, I, T][M, E, R, I, T]
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java ArrayList

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App