Arraylist - Set/ add method usage - Java

后端 未结 7 1345
渐次进展
渐次进展 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.

    0 讨论(0)
提交回复
热议问题