Arrays in Java
This collection of articles teaches you all about arrays in Java.
-
Java Arrays (with examples)
Arrays in Java have fixed length. First index is 0, last index is length-1. Arrays are objects which means they are always dynamically allocated, live on the heap and of reference type.
-
Maximum length of array
The length of an array is bound by the range of an int. This means that the maximum length is 2,147,483,647, or 2^31-1, or Integer.MAX_VALUE.
-
ArrayIndexOutOfBoundsException
An ArrayIndexOutOfBoundsException is thrown when the program tries to access an element at an index that is out of bounds for the array. For an array with N elements, the last accessible index is N-1.
-
Arrays vs ArrayLists (and other Lists)
Arrays are built in to the language while lists are part of the standard library. The most notable difference is that arrays have fixed length while lists can grow.
-
Matrices and Multidimensional Arrays
Java does not have true multidimensional arrays. Instead you typically use arrays of arrays or unfolded arrays. Both approaches has pro's and con's.
-
Appending to an array
In Java arrays can't grow, so you need to create a new array, larger array, copy over the content, and insert the new element.
-
Copying an array
Copying an array is one of the few situations where Object.clone is the preferable solution. You simply do originalArray.clone().
-
Inserting an element in an array at a given index
In Java arrays can't grow, so you need to create a new array, larger array, copy over the content, and insert the new element.
-
Testing array equality
This article explains how to check if two arrays are equal