Which is faster, Array or List?

Asked 1 years ago, Updated 1 years ago, 81 views

You need to have thousands of strings in memory that are accessible sequentially. Should I save the string to Array? Should I save it to the list? Unlike List, Array stores all data continuously in a lump of memory. If there are thousands of strings in an array, isn't that a problem?

Ask yourself: The difference in performance between the two is small, and the List interface is more flexible.

performance list java array container

2022-09-22 22:26

1 Answers

I recommend you to test which one is faster using a profiler. And I personally recommend using List. When I was working in a place with a huge code base, previous developers used arrays everywhere, which made code very inflexible. And when we switched it to List, we barely felt the difference in speed.


2022-09-22 22:26

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.