1

Possible Duplicate:
Array or List in Java. Which is faster?

I started a project where I will be constantly accessing an Arraylist that will never be changed. Would it be faster to access an ArrayList or an Array and by how much?

Community
  • 1
  • 1

2 Answers2

3

The difference will probably not be noticeable as the JVM will most likely optimise the call if you use it very often. And using List will give you a more robust and flexible code, so I would personally use Lists.

There is only one way to know: test it (after having read this post about how to test the performance of a Java application).

Community
  • 1
  • 1
assylias
  • 321,522
  • 82
  • 660
  • 783
0

if its constant, how about an Enum, you can add logic directly to the enum instances.

NimChimpsky
  • 46,453
  • 60
  • 198
  • 311