World 6 of 26 · Beginner

🧱 Arrays

12 Java concepts, each explained step by step with real code, a common trap and practice questions.

  1. Creating arraysnew int[5], array initializers {1,2,3}, fixed size.
  2. Indexing & lengthZero-based indexes, .length field (not a method).
  3. ArrayIndexOutOfBoundsExceptionAccessing index < 0 or >= length.
  4. Default element values0, false, '\u0000' or null depending on the element type.
  5. Iterating arraysIndex loops vs for-each.
  6. Arrays are objectsArray variables are references; assigning shares the same array.
  7. Copying arraysArrays.copyOf, System.arraycopy, clone() — shallow copies.
  8. Multi-dimensional & jagged arraysint[][] as array of arrays with different row lengths.
  9. The Arrays utility classsort, toString, deepToString, fill, equals, binarySearch, asList, stream.
  10. Comparing & printing arrays== and equals compare references; use Arrays.equals and Arrays.toString.
  11. Array covariance & ArrayStoreExceptionString[] is an Object[], so storing an Integer fails at runtime.
  12. Common array algorithmsSum, max, reverse, linear search, counting.