Manage arrays
In this section, we will review how array objects can be created and initialized, and where you can find methods that allow us to perform some operationsoverarrays—copy, sort, and compare, for example.
Although arrays have their place in some algorithms and legacy code, in practice an ArrayList()
can do everything an array can do and does not require setting the size upfront. In fact, an ArrayList
is using an array to store its elements at the back. So, the performance of an array and ArrayList
is comparable too.
So, we are not going to discuss array management too much beyond the basics of creation and initialization. We will provide a short overview and references on where to find the array utility methods in case you need them.
Initialize arrays
We have seen already a few examples of array construction. Now, we are going to review them and present other ways to create and initialize array objects.
Creation expression
An array creation expression includes:
- The array element type...