CHAPTER 09
Beginner
Arrays in Java
Updated: May 17, 2026
5 min read
# CHAPTER 9
Arrays in Java
1. Introduction
What if you need to store the marks of 100 students? Creating 100 separate variables is impractical. Arrays solve this by storing multiple values of the same type in a single, indexed container.2. Learning Objectives
- Declare and initialize arrays.
- Access elements by index.
- Traverse arrays using loops.
- Work with multidimensional arrays.
-
Use the
Arraysutility class.
3. Declaring and Initializing Arrays
java
4. Accessing Array Elements
Arrays use zero-based indexing: first element is at index 0.
java
5. Traversing Arrays
java
6. Multidimensional Arrays
java
7. The Arrays Utility Class
java
8. Mini Project: Student Marks System
java
9. Common Mistakes
-
ArrayIndexOutOfBoundsException: Accessing
arr[5]when the array has 5 elements (max index is 4).
-
Forgetting zero-based indexing: First element is
arr[0], notarr[1].
-
Arrays are fixed size: Once created, the size cannot change. Use
ArrayListfor dynamic sizing.
10. MCQ Quiz with Answers
Question 1
What is the index of the first element?
Question 2
How do you get the length of array arr?
Question 3
What happens if you access an invalid index?
Question 4
Which creates a 2D array?
Question 5
What is the default value of int array elements?
Question 6
Which method sorts an array?
Question 7
Can arrays change size after creation?
Question 8
What does Arrays.toString() do?
Question 9
int[] a = new int[3]; creates how many elements?
Question 10
For-each loop syntax for arrays?
11. Interview Questions
- Q: What is the difference between an Array and an ArrayList?
- Q: How do you find the largest element in an array without sorting?
- Q: What is the time complexity of searching an unsorted array?
12. Summary
Arrays store multiple values of the same type with fixed size. They use zero-based indexing. TheArrays utility class provides sort, search, copy, and comparison methods. For dynamic sizing, use ArrayList (covered in Chapter 20).