arrays
14 tutorials tagged “arrays”.
- Difference Between Array and ArrayListArray vs ArrayList in Java: fixed vs dynamic size, primitives vs objects, length vs size(), performance, and when to use each, with examples.
- ArrayIndexOutOfBoundsExceptionThe most common array error: what triggers it, how to read its message, the off-by-one and empty-array cases that cause it, and how to prevent it.
- Array LengthFind how many elements an array holds with length, why it's a field and not a method, the last valid index, empty arrays, and length vs length() vs size().
- Array of ObjectsArrays that hold objects: why a new array of objects is full of null, creating each object, looping over them, and the NullPointerException trap.
- Array ProgramsClassic array exercises with solutions: min, max and average, searching, removing duplicates, merging sorted arrays, and matrix addition.
- Passing Arrays to Methods and Returning ArraysPass an array to a method and get one back: why a method can change the caller's array, why it can't replace it, and how to return a new array safely.
- Arrays ClassThe java.util.Arrays toolbox: toString, sort, binarySearch, fill, equals, copyOf and asList, with the traps in binarySearch and asList explained.
- Copying and Cloning ArraysWhy = doesn't copy an array, and the real ways to copy: a loop, Arrays.copyOf, Arrays.copyOfRange, System.arraycopy and clone, plus shallow vs deep copies.
- Jagged Arrays2D arrays whose rows have different lengths: when they're useful, how to create each row separately, how to loop over them safely, and how they save memory.
- Java ArraysStore many values of one type under one name: declaring, creating and initializing arrays, indexes from 0, default values, and memory layout.