Alias versus copy of an ArrayList
Predict the outputMediumJava only
import java.util.*;
public class Main {
public static void main(String[] args) {
List<Integer> a = new ArrayList<>(List.of(1, 2));
List<Integer> b = a;
List<Integer> c = new ArrayList<>(a);
b.add(3);
c.add(4);
System.out.println(a);
System.out.println(b);
System.out.println(c);
}
}
This question is part of Pro+
Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.