Hello,
Trying to clone an ArrayList with all variables. As a result, I change the values of degrees in a new sheet. And automatically change the data in the old sheet. Although I use an example in which the data of the old sheet should remain unchanged.
ArrayList<HeatSensor> celsius = new ArrayList<HeatSensor>(); ArrayList<HeatSensor> fareng = (ArrayList<HeatSensor>) celsius.clone(); for(HeatSensor h: fareng) { double far = h.getCelsius(); far = 9*far/5 + 32; h.setCelsius(far); System.out.println(h.toString()); } To make it clearer, this is what is displayed on the screen:
================celsius============================ Heat : 70.0, 1/02/2017 Heat : 30.0, 1/02/2017 Heat : 35.0, 3/02/2017 ================fahrenheit========================== Heat : 158.0, 1/02/2017 Heat : 86.0, 1/02/2017 Heat : 95.0, 3/02/2017 ================celsius============================ Heat : 158.0, 1/02/2017 Heat : 86.0, 1/02/2017 Heat : 95.0, 3/02/2017 There is also another question regarding the same program. find the maximum value in ArrayList