Add object to ArrayList at specified index

前端 未结 14 1433
南笙
南笙 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:30

    You can use Array of objects and convert it to ArrayList-

    Object[] array= new Object[10];
    array[0]="1";
    array[3]= "3";
    array[2]="2";
    array[7]="7";
    
    List list= Arrays.asList(array);
    
    
    

    ArrayList will be- [1, null, 2, 3, null, null, null, 7, null, null]

    提交回复
    热议问题