Add object to ArrayList at specified index

前端 未结 14 1434
南笙
南笙 2020-11-30 18:59

I think it\'s a fairly simple question, but I can\'t figure out how to do this properly.

I\'ve got an empty arraylist:

ArrayList list =         


        
      
      
      
14条回答
  •  时光说笑
    2020-11-30 19:35

    If that's the case then why don't you consider using a regular Array, initialize the capacity and put objects at the index you want.

    Object[] list = new Object[10];
    
    list[0] = object1;
    list[2] = object3;
    list[1] = object2;
    

提交回复
热议问题