ArrayList vs. Vectors in Java if thread safety isn't a concern

后端 未结 5 2064
遇见更好的自我
遇见更好的自我 2020-12-01 03:52

Is there really that much of a difference between the performance of Vector and ArrayList? Is it good practice to use ArrayLists at all times when

5条回答
  •  臣服心动
    2020-12-01 04:31

    Vector originates back from the pre-Collections API days, and have been retrofitted since to be a part of it. From what I've read, the reason it is not deprecated is because the core API depends on it.

    ArrayList was written from scratch as a part of the Collections API and as such should be used unless you need to support Java versions down to 1.2.

    If you need a thread-safe ArrayList, you can use the static factory method Collections.synchronizedList(new ArrayList); to generate your list.

提交回复
热议问题