java arraylist ensureCapacity not working

后端 未结 8 2018
天命终不由人
天命终不由人 2020-12-03 05:18

Either I\'m doing this wrong or i\'m not understanding how this method works.

ArrayList a = new ArrayList();
a.ensureCapacity(200         


        
8条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-03 06:07

    Once again JavaDoc to clarify the situation:

    Throws: IndexOutOfBoundsException 
        - if index is out of range (index < 0 || index > size()).
    

    Note that size() returns the number of elements currently held by the List.

提交回复
热议问题