I can not understand how my data is updated in all three maps?
public void updateMap(Map<String, WagonFinalInfo> map, String wagons, String rates, String tariffs) { List<WagonRateAndTariff> listRateAndTariff = PrepareDateForInsert.fillListForUpdate(wagons, rates, tariffs); Map<String, WagonFinalInfo> oldMap = new HashMap<>(map); Map<String, WagonFinalInfo> tempNewMap = new HashMap<>(map); logger.debug("listRateAndTariff: {}", listRateAndTariff); for (Map.Entry<String, WagonFinalInfo> _map: tempNewMap.entrySet()) { for (WagonRateAndTariff list : listRateAndTariff) { if (_map.getKey().equals(list.getNumberOfWagon())) { if (_map.getValue().getRate() != (Double) list.getRate()) { _map.getValue().setRate(list.getRate()); } if (_map.getValue().getTariff() != (Double) list.getTariff()) { _map.getValue().setTariff(list.getTariff()); } } } } newMapWagonFinalInfo.putAll(tempNewMap); logger.info("newMapWagonFinalInfo: {}, oldMap: {}", newMapWagonFinalInfo, oldMap); classHandlerInsertRateOrTariff.insertDate(newMapWagonFinalInfo, oldMap); calculateYield(newMapWagonFinalInfo); } tempNewMap like in tempNewMap , and on the output I get updates both in map and in oldMap , which should not be. How does this happen?