Deciding between using arrays or collections
In this section, we'll discuss the pros and cons of using arrays and collections. We will also perform various benchmarks that measure array and collection performance. Armed with benchmark information, you can then make informed decisions as to whether arrays or collections are best suited to your specific needs. We will start by looking at arrays.
The downsides to using arrays are as follows:
- Arrays are fixed in size, meaning that once the size of the array has been changed, its size cannot be changed.
- Since arrays are fixed in size, they are not recommended for efficient memory usage.
- Arrays can only hold heterogeneous data types, and data types can be primitive and object types.
- Data elements of the
object
type can hold different types of data elements. - Arrays lack many useful methods.
The benefits of using arrays are as follows:
- Arrays have a small memory footprint and have undergone some...