As the title says, I have two ArrayLists. Strangely, setting a value on one arraylist changes that of another.
Some information: these are ArrayLists of type Entry, each of which holds an amount and a value (which is what you see in the parentheses). I'm trying to turn this array: [(5,2)(2,5)(3,2)]
into these [(1,2)] and [(4,2)(2,5)(3,2)]. i == 1 in this case, and remainingAmt == 1.
ArrayList<Entry> firstHalf = new ArrayList<Entry>();
ArrayList<Entry> secondHalf = new ArrayList<Entry>();
for(int j = 0; j<=i;j++){
firstHalf.add(rleAL.get(j));
}
for(int k = i; k<rleAL.size(); k++){
secondHalf.add(rleAL.get(k));
}
System.out.println(firstHalf);//gives (5,2)
firstHalf.get(i).setAmount(remainingAmt);
System.out.println(firstHalf);//gives (1,2) *CORRECT*
secondHalf.get(0).setAmount(rleAL.get(i).getAmount() - remainingAmt);
System.out.println(firstHalf);//gives (0,2) *WRONG*