I am aware that:
In the case of choosing between a one-dimensional array and an arraylist, arraylists should always be the preferable choice with one main exception; when collecting primitive values AND efficiency is an issue. Since the ArrayList uses arrays internally, high performance (in terms of processing time and memory footprint) is similar to arrays when performing operations on Object types. However, ArrayList performance suffers when operating on primitive types, such as int or long, since ArrayList requires all elements to be wrapped in an Object (such as Integer or Long). While autoboxing reduces the amount of code required for wrapping and unwrapping, it does not remove the performance issues, as wrapper objects are still being created.
But I am searching for a real-life example where i would be collecting primitive values AND efficiency is an issue. Can you think of one?
SCIENCE. It's very common to have one or more sensors collecting a fixed number of data values per time interval. E.g. think of hundreds of thermometers collecting the temperature every millisecond.
Or maths, where you have a matrix or vector of doubles and wish to sum / aggregate them in some way. Here the unboxing overhead would be large with many values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With