IndexOutOfBoundsException when adding to ArrayList at index

前端 未结 10 2116
既然无缘
既然无缘 2020-12-17 16:39

I get exception Exception in thread \"main\" java.lang.IndexOutOfBoundsException: Index: 1, Size: 0 for the below code. But couldn\'t understand why.

         


        
10条回答
  •  时光说笑
    2020-12-17 16:46

    ArrayList is not self-expandable. To add an item at index 1, you should have element #0.

提交回复
热议问题