Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (10.2k points)
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 all the data in a contiguous chunk of memory (unlike Lists), would the use of an array to store thousands of strings cause problems?

1 Answer

0 votes
by (46k points)
I recommend that you use a profiler to examine which is faster.

My own belief is that you should apply Lists.

I operate on a large codebase and a preceding group of developers used arrays throughout. It made the code very firm. After replacing large chunks of it to Lists we discerned no variation in speed.

Related questions

+1 vote
2 answers
0 votes
1 answer
asked Jul 27, 2019 in Java by Ritik (3.5k points)
0 votes
1 answer
0 votes
1 answer
asked Oct 23, 2019 in Java by Anvi (10.2k points)

Browse Categories

...