Array or List in Java. Which is faster?

后端 未结 30 2176
滥情空心
滥情空心 2020-11-22 04:30

I have to keep thousands of strings in memory to be accessed serially in Java. Should I store them in an array or should I use some kind of List ?

Since arrays keep

30条回答
  •  别那么骄傲
    2020-11-22 05:12

    It depends on how you have to access it.

    After storing, if you mainly want to do search operation, with little or no insert/delete, then go for Array (as search is done in O(1) in arrays, whereas add/delete may need re-ordering of the elements).

    After storing, if your main purpose is to add/delete strings, with little or no search operation, then go for List.

提交回复
热议问题