When to use a List over an Array in Java?

前端 未结 9 900
盖世英雄少女心
盖世英雄少女心 2020-11-27 06:08

In Java, when would it be preferential to use a List rather than an Array?

9条回答
  •  时光取名叫无心
    2020-11-27 06:22

    If you know how many things you'll be holding, you'll want an array. My screen is 1024x768, and a buffer of pixels for that isn't going to change in size ever during runtime.

    If you know you'll need to access specific indexes (go get item #763!), use an array or array-backed list.

    If you need to add or remove items from the group regularly, use a linked list.

    In general, dealing with hardware, arrays, dealing with users, lists.

提交回复
热议问题