Arraylist - Set/ add method usage - Java

后端 未结 7 1344
渐次进展
渐次进展 2021-01-14 06:03

I have an Arraylist of integers. My requirement is to determine if the arraylist HAS an element existing at the specified index.If YES, then a value should be set to that in

7条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-14 06:40

    ArrayList.set(index, element) will add the specified element in the list at mentioned index. This will be replace operation so list size will remain unchanged. ArrayList.add(index, element) will add the specified element in the list at mentioned index. This is not replace operation so it will first right shift all elements from the mentioned index & finally will add the element at index position. Now size = size+1.

提交回复
热议问题