Is there a real-life java example defining when it is better to use a one-dimensional array instead of an arraylist?

I know that:

When choosing between a one-dimensional array and an arraist, arraialists should always be the preferred choice with one major exception; when collecting primitive values ​​and efficiency. Since ArrayList uses internal arrays, high performance (in terms of processing time and memory size) is similar to arrays when performing operations on object types. However, ArrayList performance suffers when dealing with primitive types such as int or long, since ArrayList requires all elements to be wrapped in Object (for example, Integer or Long). While autoboxing reduces the amount of code needed for packaging and deployment, it does not eliminate performance issues because wrapper objects are still being created.

But I am looking for a real example where I collected primitive values, and efficiency is a problem. Can you think about it?

+3
source share
5 answers

SCIENCE . It often happens that one or more sensors collect a fixed number of data values ​​per time interval. For instance. think of the hundreds of thermometers that collect temperature every millisecond.

+1
source

Or mathematics, where you have a matrix or a vector of twins and want to summarize / fill them in some way. Here the unboxing overhead will be great with many meanings.

+1
source

.

, , , . , , IPv4, . , , .

, , .

, , , / /. .

0

int/float Integer .. , - . .

:

People start programming by learning C in the early days at school / university (general observation ... does not work in 100% of cases). The mentality of using an array to solve problems is awakened in our brains, and we tend to try to use arrays. Although people come up with problems, people think in terms of arrays.

0
source

I used arrays anytime I created a byte buffer. If you know the exact size of the structure (as you probably should for a buffer), it is much easier and faster to use an array rather than a collection.

0
source

All Articles