Java previous elements in ArrayList/List being overwritten when changing next element

前端 未结 2 348
后悔当初
后悔当初 2021-01-19 06:14

I am a bit new to Java. In the forLoop below, I am looping over the elements of the arraylist and I am trying to change the position object. When the forLoop is finished, th

2条回答
  •  逝去的感伤
    2021-01-19 06:49

    Make sure that you didn't put the same instance of the object in all positions of the array list - in other words add the same element over and over again. That's what would probably cause the behavior you're seeing.

提交回复
热议问题