for (int rowNum = 1; rowNum < sheet.getLastRowNum(); rowNum++) {
Row row = sheet.getRow(rowNum);
Employee instance = methodToGetInstance(parameters);
originalList.add(instance);
}
List<Employee> copy = new ArrayList<>(originalList);
List<Employee> totalCopy = new ArrayList<>(originalList);
while (startDate.isBefore(ChronoLocalDate.from(SecurityUtils.now().plusMonths(3)))) {
int index = 0;
for (Employee instance : copy) {
instance.setStartDateTime(startDateTime); //here i'm updating the value in copyList
instance.setEndDateTime(startDateTime.plusHours(24));
totalCopy.add(instance);
index++;
}
}
Here i m updating values in instance which is from Copied List it also affecting the OriginalList.
Please help me to resolve this issue...!!