Improving performance with arrays
Previously, we discussed ArrayList
; in this section, we will focus on arrays. There are key differences in these two data types: arrays have a fixed size, while ArrayLists do not. In this section, we will review the characteristics of arrays and how to improve the performance of our Java applications when implementing arrays.
Array characteristics
There are four primary characteristics of arrays. Let’s take a look:
- Size: The size of an array is determined when it’s created. It cannot be changed when the application is running. This fixed-sized characteristic is also referred to as static. Here’s the syntax for creating an array:
int[] myNumbers = new int[10];
As you can see, we explicitly specify a size of
10
as part of the array’s declaration. - Homeogeneous: Homeogeneous means that all data in an array must be of the same kind. As with the previous example, we created an array of integers. We could have used...