When to use a List over an Array in Java?

前端 未结 9 914
盖世英雄少女心
盖世英雄少女心 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:33

    Always prefer lists.

    Arrays when

    1. Varargs for a method ( I guess you are forced to use Arrays here ).
    2. When you want your collections to be covariant ( arrays of reference types are covariant ).
    3. Performance critical code.

提交回复
热议问题