Java Arrays & Multi-Dimensional Arrays Quiz
35 deep and practical questions on Java arrays — from declaration and initialization to advanced 2D/3D usage, Arrays utility methods, common pitfalls, and performance gotchas that trip even senior developers.
Question 1
What is the output?
int[] arr = new int[5];
System.out.println(arr[2]);Question 2
What is the value of arr.length in this declaration?
String[][] matrix = { {"a", "b"}, {"c", "d", "e"}, {"f"} };Question 3
What is printed?
int[] nums = {10, 20, 30};
int[] copy = Arrays.copyOf(nums, 5);
System.out.println(copy[3] + " " + copy[4]);Question 4
Which of these is NOT a valid way to declare a 2D array?
Question 5
What is the output?
Object[] objects = new String[10];
objects[0] = Integer.valueOf(42);
System.out.println("No exception");Question 6
What is printed?
int[][] table = new int[3][];
table[0] = new int[] {1, 2};
table[1] = new int[] {3, 4, 5};
table[2] = new int[1];
System.out.println(table[1].length);Question 7
Which method correctly compares two 2D arrays for deep equality?
Question 8
What is the output?
int[] data = {5, 2, 8, 1};
Arrays.sort(data);
System.out.println(Arrays.binarySearch(data, 2));Question 9
What is printed?
boolean[] flags = new boolean[3];
System.out.println(flags[0] + " " + flags[1]);Question 10
What happens here?
int[] source = {1, 2, 3};
int[] target = source;
target[0] = 99;
System.out.println(source[0]);Question 11
What is the output?
int[] nums = new int[] {10, 20};
int[] clone = nums.clone();
clone[0] = 999;
System.out.println(nums[0] + " " + clone[0]);Question 12
Which loop is generally preferred for iterating over an array?
Question 13
What is printed?
int[][][] cube = new int[2][3][4];
System.out.println(cube[1][2].length);Question 14
What is the result?
int[] arr = {1, 2, 3};
Arrays.fill(arr, 42);
System.out.println(Arrays.toString(arr));Question 15
What is printed?
String[] words = {"java", "python", "js"};
Arrays.sort(words);
System.out.println(words[0]);Question 16
How many objects are created by this line?
int[][] grid = new int[3][4];Question 17
Which of these creates an array with values 0, 0, 0, 0, 0?
Question 18
What is the default value of elements in an Object array?
Question 19
What is the output?
int[] a = {1, 2};
int[] b = {1, 2};
System.out.println(Arrays.equals(a, b));Question 20
Why is this considered a serious bug?
private int[] data = {1, 2, 3};
public int[] getData() { return data; }Question 21
What is the result of Arrays.asList on a primitive array?
Question 22
Which statement about array length is correct?
Question 23
What is printed?
char[] chars = {'J', 'a', 'v', 'a'};
String s = new String(chars, 1, 3);
System.out.println(s);Question 24
What is the fastest way to copy an array?
Question 25
What is the output?
int[] arr = new int[0];
System.out.println(arr.length);Question 26
Can you change the length of an array after creation?
Question 27
What is printed?
int[][] irregular = {{1}, {2, 3}, {4, 5, 6}};
System.out.println(irregular[2][1]);Question 28
Which method returns a formatted string like [1, 2, 3]?
Question 29
What is the result of Arrays.binarySearch on an unsorted array?
Question 30
What is the most important rule when working with arrays?
Question 31
Can an array’s component type be a primitive?
Question 32
What is printed?
byte[] bytes = new byte[2];
bytes[0] = 100;
bytes[1] = 100;
System.out.println(bytes[0] + bytes[1]);Question 33
What is the result?
int[] arr = null;
System.out.println(arr.length);Question 34
Which of these is true about Arrays.parallelSort?
Question 35
After mastering arrays, you now know that:
