I create an arrayList and set all it's elements to 0
When all elements are set to 1, I try to turn them all back to 0 with a lambda and only the first 2 indices are changed.
// create a list freeFrames, size 5, all elements set to 0:
List<Integer> freeFrame = new ArrayList<Integer>(Collections.nCopies(5, 0));
// freeFrame= [0, 0, 0, 0, 0]
// code executes and eventually freeFrame =[1, 1, 1, 1, 1]
// try to change all values to 0 if none are present
if(!freeFrame.contains(0))
freeFrame.forEach((b) -> freeFrame.set(b, 0));
// freeFrame= [0, 0, 1, 1, 1]
I ended up using a standard loop. Why are only the first 2 indexes getting changed with the above? This post seemed close https://stackoverflow.com/a/20040292/20419870 but I don't think I'm changing the size of the list, just changing the values. This one https://stackoverflow.com/a/56399619/20419870 suggests to use stream and map to safely modify the list while iterating. I had thought only removing and adding to list while iterating was unsafe, does modifying the contents cause an exception I'm not seeing?