My problem is that I need to copy a list but a deep copy. When I modify the list a
, I don't want to modify the list b
. I use JDK11 so I could use list.copyOf
but using that when I modify a
, b
is also modified. Am I doing something wrong?
b = List.copyOf(a);
System.out.println("A start:" + b.get(2).getSeating());
System.out.println("B start:" + b.get(2).getSeating());
a.get(2).setSeating(27);
System.out.println("Hi there" );
System.out.println("A end:" + a.get(2).getSeating());
System.out.println("B end:" + b.get(2).getSeating());
The output of that assignation: