Why not always use ArrayLists in Java, instead of plain ol' arrays?

后端 未结 5 601
陌清茗
陌清茗 2020-12-03 18:17

Quick question here: why not ALWAYS use ArrayLists in Java? They apparently have equal access speed as arrays, in addition to extra useful functionality. I understand the

5条回答
  •  醉梦人生
    2020-12-03 19:13

    Performance should not be your primary concern.

    Use List interface where possible, choose concrete implementation based on actual requirements (ArrayList for random access, LinkedList for structural modifications, ...).

    You should be concerned about performance.

    Use arrays, System.arraycopy, java.util.Arrays and other low-level stuff to squeeze out every last drop of performance.

提交回复
热议问题