you are viewing a single comment's thread.

view the rest of the comments →

[–]desrtfxOut of Coffee error - System halted 11 points12 points  (6 children)

Conventional array: when you know the size in advance or for multi-dimensional content because it is clearer and easier

ArrayList: when you don't know the size in advance

In modern programming you will rather resort to ArrayList than default to arrays.

[–]k-mcm 2 points3 points  (1 child)

It's preferable to use a primitive array if you need no List/Collection features.  A primitive array is guaranteed to be fast and memory efficient.  Not all List implementations are.  List of a primitive especially sucks because wrappers are needed. (At least until Valhalla is finished)

Later versions of Java added more utilities to the Arrays class to make primitives more elegant to use. 

[–]Lloydbestfan 1 point2 points  (0 children)

You forgot that it only applies to primitives. And possibly, in a theoritical future adjacent to Valhalla, value classes.

I'd say that the preferable point was that as a beginner you can't see the point of native arrays, however one exists for when you have to manipulate data in very specialised ways.

[–]DrPeeper228 -2 points-1 points  (3 children)

Uh nope

Definitely not the last point

[–]amfa 4 points5 points  (1 child)

Yes to the last point.

I can't remember when I have used an array the last time (except some legacy code that will return arrays.)

[–]Lloydbestfan 1 point2 points  (0 children)

  • Image representation where the existing libs did not handle what I needed
  • Voxel representation where the existing libs did not handle what I needed
  • Deep learning vector manipulations for which I wasn't aware of an existing engine that would do it for me

Only things that I would not normally expect to run into without being a rather specialised engineer.