I used the method below to make a copy of a list, as you can see the output, they are independent. Did I get something wrong? or are they really independent? because I did some research on the internet, and it told me this method should pass-by-reference (which list 'a' and 'copy' should be dependent).
public static void main(String[] args) {
ArrayList<String> a = new ArrayList<>(Arrays.asList("X", "X"));
ArrayList<String> copy = new ArrayList<>(a);
copy.set(0, "B");
copy.remove(copy.size()-1);
System.out.println(a);
System.out.println(copy);
}
Output:
[X, X]
[B]