Skip to main content
Elaborated.
Source Link
James Dunn
  • 8.3k
  • 14
  • 55
  • 88

Is my gut instinct correct, or are lists truly as efficient as arrays?
Neither. Lists are not truly"truly" as efficient as Arrays (although ArrayLists are close), but this doesn't mean that the performance costany optimization necessarily outweighs the flexibility benefits, even if you have thousands of operations going on.

Consider these questions:

  • Does this application need to be really, really fast?
  • Is the part of the code using either Arrays or Lists highly unlikelynever going to be further developed?

If the answer to both of these questions is yes, then use Arrays. Otherwise, use Lists.

But since the performance between Arrays and Lists (particularly the ArrayList implementation) isn't that much, and since your code is highly likely to be developed further...
...just use Lists.

Is my gut instinct correct, or are lists truly as efficient as arrays?
Neither. Lists are not truly as efficient as Arrays, but this doesn't mean that the performance cost necessarily outweighs the flexibility benefits, even if you have thousands of operations going on.

Consider these questions:

  • Does this application need to be really, really fast?
  • Is the part of the code using either Arrays or Lists highly unlikely to be further developed?

If the answer to both of these questions is yes, then use Arrays. Otherwise, use Lists.

Is my gut instinct correct, or are lists truly as efficient as arrays?
Neither. Lists are not "truly" as efficient as Arrays (although ArrayLists are close), but this doesn't mean that any optimization necessarily outweighs the flexibility benefits, even if you have thousands of operations going on.

Consider these questions:

  • Does this application need to be really, really fast?
  • Is the part of the code using either Arrays or Lists never going to be further developed?

If the answer to both of these questions is yes, then use Arrays. Otherwise, use Lists.

But since the performance between Arrays and Lists (particularly the ArrayList implementation) isn't that much, and since your code is highly likely to be developed further...
...just use Lists.

Source Link
James Dunn
  • 8.3k
  • 14
  • 55
  • 88

Is my gut instinct correct, or are lists truly as efficient as arrays?
Neither. Lists are not truly as efficient as Arrays, but this doesn't mean that the performance cost necessarily outweighs the flexibility benefits, even if you have thousands of operations going on.

Consider these questions:

  • Does this application need to be really, really fast?
  • Is the part of the code using either Arrays or Lists highly unlikely to be further developed?

If the answer to both of these questions is yes, then use Arrays. Otherwise, use Lists.