Why does list insertion fail when sufficient size is provided on construction?

前端 未结 8 868
北恋
北恋 2020-12-20 20:47

If we have the following variable declaration:

List list = new List(5);

Why does this:

list.insert(2, 3);
         


        
8条回答
  •  [愿得一人]
    2020-12-20 21:11

    The size in the constructor tells it how much to allocate for the background array - it is still, however, empty (just: empty with a certain amount of initial space).

    You can ony insert into the used part of the list, or at the end.

提交回复
热议问题