Java ArrayList replace at specific index

后端 未结 5 2141
说谎
说谎 2020-11-27 13:36

I need help with this java please. I created an ArrayList of bulbs, and I\'m trying to replace a bulb at specific index with another bulb. So with the following heading, how

5条回答
  •  迷失自我
    2020-11-27 14:13

    You can replace the items at specific position using set method of ArrayList as below:

    list.set( your_index, your_item );
    

    But the element should be present at the index you are passing inside set() method else it will throw exception.

提交回复
热议问题