Array or List in Java. Which is faster?

后端 未结 30 2164
滥情空心
滥情空心 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:02

    Arrays recommended everywhere you may use them instead of list, especially in case if you know items count and size would not be changing.

    See Oracle Java best practice: http://docs.oracle.com/cd/A97688_16/generic.903/bp/java.htm#1007056

    Of course, if you need add and remove objects from collection many times easy use lists.

提交回复
热议问题