Arrays in Java

This collection of articles teaches you all about arrays in Java.

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. Copying an array
    Copying an array is one of the few situations where Object.clone is the preferable solution. You simply do originalArray.clone().
  7. 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.
  8. Testing array equality
    This article explains how to check if two arrays are equal