I first noticed this problem when I only put the objects in listOfRates and then created inverseListOfRates by copying it. But even using this method, I can't alter one list without altering the other.
How do I solve this issue?
List<HistoricRate> listOfRates = new ArrayList<HistoricRate>();
List<HistoricRate> inverseListOfRates = new ArrayList<HistoricRate>();
for (HistoricRate rate : rates){
listOfRates.add(rate);
inverseListOfRates.add(rate);
}
inverseListOfRates.forEach(r -> r.setMid(1 / r.getMid()));