My problem is that I want to copy an ArrayList with Objects in it.
Afterwards i want to change the Objects within my "copy List" without changing the Object within the source List.
I already tried:
ArrayList<..> copy = new ArrayList<..>(sourceList);
Collections.copy(dest, src);
The more specific problem is here:
ArrayList<Exon> regions1 = new ArrayList<>();
regions1.add(r1);
regions1.add(r2);
regions1.add(r3);
System.out.println("Reg 1");
for (Exon e : regions1) {
System.out.println(e.getStart());
}
ArrayList<Exon> copy = new ArrayList<>(regions1);
System.out.println("Copy");
for (Exon e : copy) {
e.setStart(2);
System.out.println(e.getStart());
}
System.out.println("Reg 1 - untouched");
for (Exon e : regions1) {
System.out.println(e.getStart());
}
The Output I get is:
Reg 1
5
15
100
Copy
2
2
2
Reg 1
2
2
2
The Output I would want is:
Reg 1
5
15
100
Copy
2
2
2
Reg 1
5
15
100