QuickDevGuide

Home › Java

Arrays — Java

An array is a fixed-size, zero-indexed container of one type. Arrays are objects: they live on the heap and have a length field (not a method). Declaring and creating int[] nums = new int[5]; (filled with defaults: 0, false, null) or int[] nums = {3, 1, 2};. java.util.Arrays helpers Method Purpose Arrays.toString(arr) / deepToString Printable form Arrays.sort(arr) In-place sort (dual-pivot quicksort for primitives) Arrays.binarySearch(arr, key) O(log n) search on a sorted array Arrays.fill(arr, v) Fill every slot Arrays.copyOf(arr, n) / copyOfRange Copy / resize Arrays.equals(a, b) Compare contents (== compares references) Arrays.asList(...) / Arrays.stream(arr) Bridge to collections and streams Array vs ArrayList Use arrays for fixed-size, performance-critical or primitive data; use…

Key Takeaways