我有三个列表,在第三个列表中我正在合并两个列表。如果我在第三个中进行更改,为什么更改会反映到其他列表以及如何克服?
List<Communication> communicationFromList = fromTicket.getCommunications();
List<Communication> communicationToList = toTicket.getCommunications();
List<Communication> mergedCommunication=new ArrayList<>();
mergedCommunication.addAll(communicationToList);
mergedCommunication.addAll(communicationFromList);
for (int i = index; i < mergedCommunication.size(); i++) {
if (!ObjectUtils.isEmpty(mergedCommunication.get(i))) {
int j =i;
Communication communication = mergedCommunication.get(i);
communication.setCommSeqId(++j);
communication.setMergeInfo("Merged From: " + fromTicketId);
}
}
由于上述更改也反映到其他列表中。如何克服