In Java, an array is a dynamically allocated object used to store a fixed-size sequential collection of elements of the exact same data type. Once an array is instantiated, its size cannot be altered, ensuring contiguous memory allocation for highly efficient index-based data retrieval. Unlike arrays in C or C++, Java arrays are treated strictly as objects, inherently providing a length property to safely determine their size at runtime. Furthermore, Java natively supports multi-dimensional arrays implemented internally as “arrays of arrays” which allows for the creation of memory-efficient jagged (or ragged) structures. Utilizing the java.util.Arrays utility class provides developers with powerful built-in methods for sorting, searching, and manipulating array data securely.
Latest Java Arrays MCQs
1 min read
Correct Answer: a) 0
Explanation:
In Java, primitive type array elements (like int) are automatically initialized to their default values, which is 0 for integers.
Correct Answer: c) Both a and b
Explanation:
Both options a and b are valid syntaxes for declaring and initializing an array in Java.
Correct Answer: c) 0
Explanation:
Java arrays are zero-indexed, meaning the first element is always at index 0.
Correct Answer: b) ArrayIndexOutOfBoundsException
Explanation:
Accessing an invalid index throws java.lang.ArrayIndexOutOfBoundsException at runtime.
Correct Answer: a) int
Explanation:
The length property of an array returns an integer value representing the total number of elements in the array.
Correct Answer: c) numbers.length
Explanation:
For arrays, length is a final field (not a method), so it is accessed without parentheses as numbers.length.
Correct Answer: b) It throws a NegativeArraySizeException
Explanation:
Specifying a negative size during array creation throws a runtime NegativeArraySizeException.
Correct Answer: b) Arrays are objects in Java.
Explanation:
Arrays are dynamically created objects in Java that inherit from the Object class and are stored in heap memory.
Correct Answer: b) null
Explanation:
Reference type array elements are initialized to null by default.
Correct Answer: d) All of the above
Explanation:
All listed syntaxes are valid ways to declare a multi-dimensional array in Java.
Correct Answer: b) A multi-dimensional array with rows of different lengths
Explanation:
A jagged array is an array of arrays where each row can have a different number of columns.
Correct Answer: a) java.util
Explanation:
The java.util.Arrays class contains static methods for sorting, searching, comparing, and filling arrays.
Correct Answer: b) Arrays.sort(arr)
Explanation:
Arrays.sort() is the standard static method provided in java.util.Arrays to sort arrays.
Correct Answer: b) The array must be sorted
Explanation:
Binary search algorithms require the underlying collection or array to be sorted beforehand to function correctly.
Correct Answer: c) A negative insertion point value
Explanation:
If the key is not found, binarySearch returns (-(insertion point) - 1).
Correct Answer: b) Arrays.equals(arr1, arr2)
Explanation:
The equals method in java.util.Arrays compares the contents of two arrays, whereas arr1.equals(arr2) on arrays checks reference equality unless overridden.
Correct Answer: b) A hash string like [I@1b6d3586
Explanation:
Arrays do not override the toString() method from Object, so printing an array directly outputs its type representation and hashcode.
Correct Answer: a) Arrays.toString(arr)
Explanation:
Arrays.toString() returns a string representation of the contents of the specified array.
Correct Answer: c) No, arrays have a fixed size once instantiated
Explanation:
Java arrays have a fixed length determined at the time of creation and cannot be resized. ArrayList should be used if dynamic sizing is needed.
Correct Answer: a) The changes are reflected outside the method because arrays are reference types.
Explanation:
Although Java passes object references by value, modifying the contents of the array reference affects the underlying heap object visible to the caller.
Correct Answer: a) new int[] {1, 2, 3}
Explanation:
An anonymous array is created without explicitly naming it using the syntax new type[] {elements}.
Correct Answer: b) ArrayStoreException
Explanation:
Trying to store a runtime type that is not assignment-compatible with the array's component type throws ArrayStoreException.
Correct Answer: d) Both b and c
Explanation:
Both System.arraycopy() and Arrays.copyOf() provide efficient built-in mechanisms for copying array data.
Correct Answer: a) Source array, source position, destination array, destination position, and length
Explanation:
System.arraycopy(src, srcPos, dest, destPos, length) copies a specified portion of an array.
Correct Answer: b) For-each loop (enhanced for loop)
Explanation:
The enhanced for-each loop simplifies iteration over arrays and collections without needing explicit index counters.
Correct Answer: b) No, because the iteration variable holds a copy of the element value.
Explanation:
In a for-each loop, the loop variable is a copy of the array element value; modifying it does not change the array elements.
Correct Answer: b) Heap memory
Explanation:
All objects, including arrays, are allocated in the heap memory in Java.
Correct Answer: a) Stack memory
Explanation:
Local variables and object references (like the array pointer itself) are stored on the thread's stack, while the actual array object resides on the heap.
Correct Answer: b) 0
Explanation:
The array elements are initialized to 0, so accessing index 1 returns 0.
Correct Answer: a) boolean[] arr = new boolean[3];
Explanation:
The default value for boolean elements in an uninitialized array is false.
Correct Answer: a) Arrays.fill(arr, 7);
Explanation:
Arrays.fill() assigns the specified value to each element of the specified array.
Correct Answer: a) It handles multi-dimensional arrays properly.
Explanation:
Arrays.deepToString() is required for nested/multi-dimensional arrays; otherwise, Arrays.toString() would print reference hashes for inner arrays.
Correct Answer: b) false
Explanation:
The equality operator checks for reference equality (whether both point to the exact same object in heap memory), not content equality.
Correct Answer: a) int[] copy = arr.clone();
Explanation:
Arrays implement the Cloneable interface, and the clone() method creates a shallow copy of the array.
Correct Answer: b) Shallow copy
Explanation:
The clone() method creates a shallow copy, meaning for object arrays, the references are copied, not the underlying objects themselves.
Correct Answer: b) N - 1
Explanation:
Since Java arrays are 0-indexed, an array of size N has indices ranging from 0 to N - 1.
Correct Answer: c) Compile-time error
Explanation:
Array size must be an integer (int, byte, short, char). Using floating-point values causes a compile-time type mismatch error.
Correct Answer: c) Both a and b
Explanation:
Both traditional array syntax and varargs (variable arguments) syntax allow passing arrays or comma-separated lists into methods.
Correct Answer: a) It allows passing zero or multiple arguments which are treated inside the method as an array.
Explanation:
Varargs syntactic sugar lets callers pass individual arguments or an array, packaging them into an array inside the method body.
Correct Answer: c) No, standard arrays are homogeneously typed
Explanation:
Java arrays are strictly homogeneous; an array declared of a specific type can only hold elements of that type or its subtypes.
Correct Answer: a) By using an array of type Object
Explanation:
Since all classes inherit from Object, an Object array can store references to various types of objects.
Correct Answer: b) false
Explanation:
The a and b variables point to two different array objects in heap memory, so reference equality evaluates to false.
Correct Answer: a) true
Explanation:
Arrays.equals() checks content equality, and since both arrays contain the exact same elements in the same order, it returns true.
Correct Answer: c) int[] a = new int[];
Explanation:
Omitting the size when instantiating an array with new without providing initializer values is a compilation error.
Correct Answer: a) O(1)
Explanation:
Array elements are stored in contiguous memory locations, allowing direct random access in constant time O(1).
Correct Answer: c) O(N)
Explanation:
Linear search requires checking each element one by one in the worst case, taking O(N) time.
Correct Answer: b) O(N log N)
Explanation:
Java uses Dual-Pivot Quicksort for primitive arrays, which runs in O(N log N) average time complexity.
Correct Answer: b) TimSort
Explanation:
Java uses an adaptive, stable mergesort variant called TimSort for sorting object arrays.
Correct Answer: b) Arrays have a fixed size and lack built-in methods for insertion/deletion.
Explanation:
Arrays are static in size and do not provide helper methods like add(), remove(), or dynamic resizing.
Correct Answer: c) Both a and b
Explanation:
Both options a and b represent valid 3D array declarations in Java.
Correct Answer: a) The number of command-line arguments passed to the program
Explanation:
The String[] args parameter in the main method holds command-line arguments, and args.length gives the count of those arguments.
Correct Answer: a) 0
Explanation:
An array of size 0 is completely valid in Java and has a length of 0.
Correct Answer: a) int[][] m = {{1, 2}, {3, 4}};
Explanation:
Array initializer blocks using nested braces are the standard way to inline initialize multi-dimensional arrays.
Correct Answer: b) No, it must be an int or a type implicitly promotable to int
Explanation:
Java array indices are constrained to integer types because array sizes and index values cannot exceed Integer.MAX_VALUE.
Correct Answer: b) Integer.MAX_VALUE
Explanation:
Because array indexing uses int, the maximum capacity of an array is Integer.MAX_VALUE.
Correct Answer: a) Compile-time error
Explanation:
Passing a literal or expression exceeding integer bounds directly as an array size results in a compile-time integer number too large error.
Correct Answer: a) Arrays.compare()
Explanation:
Introduced in Java 9, Arrays.compare() compares two arrays lexicographically and returns a negative integer, zero, or a positive integer.
Correct Answer: a) Arrays.asList(arr)
Explanation:
Arrays.asList() returns a fixed-size list backed by the specified array.
Correct Answer: a) It is immutable in size (cannot add or remove elements).
Explanation:
The list returned is a fixed-size view backed by the original array; calling add() or remove() throws an UnsupportedOperationException.
Correct Answer: a) -1
Explanation:
Arrays.mismatch() finds and returns the index of the first mismatching element between two arrays, or -1 if they are identical.
Correct Answer: c) Both a and b
Explanation:
Both options are valid ways to declare and initialize a string array.
Correct Answer: b) 10
Explanation:
Variables x and y reference the same array object in memory, so modifications through y affect x as well.
Correct Answer: a) Cloneable and Serializable
Explanation:
Java arrays implement both java.lang.Cloneable and java.io.Serializable interfaces.
Correct Answer: b) No, array types are implicitly final.
Explanation:
Array classes are generated by the JVM and are implicitly final, meaning you cannot extend them.
Correct Answer: a) true
Explanation:
The default value for char elements in an array is the null character, whose numeric integer code is 0.
Correct Answer: a) grid.length
Explanation:
A 2D array in Java is an array of arrays. Its primary length gives the number of rows.
Correct Answer: b) grid[0].length
Explanation:
grid[0] refers to the first row array, and its length property provides the number of columns in that row.
Correct Answer: a) parallelSort uses parallel sorting algorithms to leverage multiple processors for large arrays.
Explanation:
Arrays.parallelSort() uses the parallel merge sort algorithm to cut down sorting time on multi-core processors for large datasets.
Correct Answer: b) It is performed at runtime by the JVM.
Explanation:
Java enforces strict bounds checking at runtime, throwing an ArrayIndexOutOfBoundsException whenever an invalid index is accessed.
Correct Answer: a) A hash code based on the array's memory address
Explanation:
System.identityHashCode returns the standard object hash code based on memory address, unaffected by overridden hashCode methods.
Correct Answer: b) The reference variable no longer points to any array object on the heap.
Explanation:
Assigning null to the reference variable disconnects it from the array object, making the array eligible for garbage collection if no other references remain.
Correct Answer: a) NullPointerException
Explanation:
Attempting to query properties like length or index elements on a null reference throws a NullPointerException.
Correct Answer: a) Yes, arrays can be used as type parameters, but primitive types cannot.
Explanation:
Generics require reference types; primitive types like int cannot be type parameters, but array types like int[] are reference types and are valid.
Correct Answer: a) Arrays.stream(arr)
Explanation:
Arrays.stream() is the utility method used to create a Stream from an array.
Correct Answer: b) Collections.reverse(Arrays.asList(arr)) for object arrays
Explanation:
Java's Arrays class does not have a direct built-in reverse method; object arrays can be reversed via Collections.reverse().
Correct Answer: a) 30
Explanation:
The enhanced for loop sums up 5 + 10 + 15, which equals 30.
Correct Answer: c) Both a and b
Explanation:
Both traditional array notation and varargs notation are valid for the main method parameter signature.
Correct Answer: a) A hash code based on the contents of the array
Explanation:
Arrays.hashCode() calculates a hash code derived from the contents of the array, ensuring arrays with identical elements produce the same hash.
Correct Answer: b) No, combining explicit size with an array initializer block is a compilation error.
Explanation:
You cannot specify both the dimension size (e.g., new int[3]) and initializer values ({1, 2, 3}) simultaneously in Java syntax.
Correct Answer: b) new
Explanation:
The 'new' keyword is used to instantiate arrays and allocate memory on the heap.
Correct Answer: a) java.lang.Object
Explanation:
Every array in Java directly inherits from java.lang.Object.
Correct Answer: b) No, the reference to the original array is passed by value.
Explanation:
Java is pass-by-value; the value passed is the reference pointer pointing to the array object on the heap, not a duplicate of the array itself.
Correct Answer: a) Arrays.fill(arr, fromIndex, toIndex, val)
Explanation:
The overloaded Arrays.fill() method allows specifying fromIndex (inclusive) and toIndex (exclusive) to fill a specific range.
Correct Answer: b) It is exclusive.
Explanation:
In Java range methods, the 'toIndex' parameter is exclusive, meaning the element at 'toIndex' is not included in the operation.
Correct Answer: b) Elements from index 1 up to index 4 (exclusive of index 4)
Explanation:
It copies elements starting from index 1, 2, and 3, stopping before index 4.
Correct Answer: a) Yes
Explanation:
Object arrays can store any reference type, including null.
Correct Answer: a) 'int[] a' is preferred by convention, but both are semantically identical in Java.
Explanation:
Both notations are valid, though 'int[] a' clearly associates the brackets with the type rather than the variable name.
Correct Answer: a) int[][] table = new int[3][];
Explanation:
You can specify the size of the first dimension and leave subsequent dimensions empty to create a jagged array structure.
Correct Answer: a) It prints null
Explanation:
The inner array references in a jagged array default to null until explicitly instantiated.
Correct Answer: d) All of the above
Explanation:
All listed statements successfully create an array capable of holding 5 integers.
Correct Answer: b) 99
Explanation:
The method modifies the array element via the reference, so the change persists outside the method scope.
Correct Answer: a) 5
Explanation:
The method reassigns the local parameter variable to a new array, leaving the caller's reference pointing to the original array containing 5.
Correct Answer: a) Arrays.deepToString(matrix)
Explanation:
Arrays.deepToString() recursively formats multi-dimensional arrays into a readable string.
Correct Answer: a) Yes, but it only prevents reassigning the reference variable, not modifying the array's elements.
Explanation:
A final array variable cannot point to a different array object once initialized, but its individual elements can still be mutated.
Correct Answer: a) They allow storing and managing collections of related data values under a single identifier.
Explanation:
Arrays group multiple variables of the same type together, enabling efficient loops and batch data processing.
Correct Answer: a) An array of Sub can be assigned to a variable of type Super[].
Explanation:
Java arrays are covariant, meaning assigning a subclass array to a superclass array reference is valid at compile-time.
Correct Answer: a) Yes, e.g., obj instanceof int[]
Explanation:
Arrays are objects in Java, and instanceof can check if a reference points to a specific array type.
Correct Answer: a) [I
Explanation:
The internal JVM representation for a 1D integer array class name is '[I'.
Correct Answer: a) java.lang.reflect.Array.newInstance(type, length)
Explanation:
The Array.newInstance method in the reflection API allows dynamic creation of arrays at runtime.
Correct Answer: a) ArrayStoreException
Explanation:
Due to covariance, an Object[] can hold a String[]. Adding a non-String element throws ArrayStoreException at runtime.
Correct Answer: a) No, because generic type information is erased at runtime.
Explanation:
Java generics use type erasure, meaning the JVM does not know what type 'T' is at runtime to allocate the array.
Correct Answer: a) Compile-time error: generic array creation
Explanation:
Java strictly forbids creating arrays of parameterized types to prevent type safety issues.
Correct Answer: a) Two nested loops
Explanation:
Traversing a 2D matrix generally requires an outer loop for rows and an inner loop for columns.
Correct Answer: a) ArrayIndexOutOfBoundsException
Explanation:
Accessing index 0 on an empty array (length 0) goes out of bounds.
Correct Answer: a) Arrays do not have a separate capacity; length is the fixed capacity.
Explanation:
Unlike ArrayLists which track size vs capacity, standard arrays only have a fixed 'length'.
Correct Answer: a) You cannot; you must create a new array and copy the elements.
Explanation:
Arrays are statically sized. To 'resize', a new array must be created and elements copied over.
Correct Answer: a) It prints the actual characters as a String.
Explanation:
The PrintStream class has an overloaded method for char[], which prints the array contents directly as a text string instead of printing the object hash.
Correct Answer: a) Yes, and it can store references to any object implementing that interface.
Explanation:
You can declare an array of an interface type, storing any class instance that implements the interface.
Correct Answer: a) Yes, it can store references to objects of its concrete subclasses.
Explanation:
While abstract classes cannot be instantiated, an array of an abstract class type can be created to hold subclass objects.
Correct Answer: a) Compile-time error
Explanation:
When declaring multi-dimensional arrays, you must specify the size of the most significant (leftmost) dimension.
Correct Answer: a) int array, because it stores primitive values directly in a contiguous block.
Explanation:
A primitive array avoids the object header overhead and boxing wrapper classes associated with ArrayList.
Correct Answer: a) No, primitive arrays and Object wrapper arrays are not compatible for casting.
Explanation:
Autoboxing works for individual elements, but you cannot cast an entire primitive array to a wrapper object array.
Correct Answer: a) Object[]
Explanation:
The no-arg list.toArray() always returns an Object array. The overloaded list.toArray(T[] a) is needed for specific typing.
Correct Answer: a) A new array of the same runtime type is allocated with the size of the List.
Explanation:
If the provided array is too small, a new array of the identical component type and sufficient size is allocated via reflection.
Correct Answer: a) Yes
Explanation:
Arrays are basic data structures that do not enforce uniqueness, allowing any number of duplicates.
Correct Answer: a) No, primitives cannot be null.
Explanation:
Null is a reference type literal. Primitive variables and arrays cannot hold null values.
Correct Answer: a) No, external synchronization is required for concurrent access.
Explanation:
Arrays have no built-in thread safety mechanisms. Concurrent reads and writes can lead to race conditions.
Correct Answer: a) No, only the reference itself is volatile.
Explanation:
In Java, marking an array volatile ensures thread visibility for the array reference, not for individual array elements.
Correct Answer: a) Returns a hash code based on the deep contents of the array.
Explanation:
For multi-dimensional arrays or arrays of arrays, deepHashCode computes a hash based on the values of the inner arrays recursively.
Correct Answer: a) Arrays.spliterator(arr)
Explanation:
Introduced in Java 8, Arrays.spliterator() creates a Spliterator for parallel or sequential traversal of the array elements.
Correct Answer: a) At runtime upon execution of the 'new' keyword.
Explanation:
All array allocations occur at runtime on the heap using the new keyword or array initializer syntax.
Correct Answer: a) Yes, the character 'a' is implicitly promoted to an integer size.
Explanation:
Characters in Java are 16-bit integers under the hood. The character promotes to its integer code, creating an array of that size.
Correct Answer: a) 255 dimensions
Explanation:
The Java Virtual Machine specification limits array dimensions to 255.
Correct Answer: a) Yes, they are implicitly promoted to int.
Explanation:
Smaller integer types (byte, short, char) are automatically promoted to int, making them perfectly valid for array indexing.
Related Posts

Latest JavaScript Basics MCQs
JavaScript is a high-level, dynamic, single-threaded interpreted programming language that powers modern interactive web applications. Key foundational concepts include dynamic…
October 19, 2026By MCQs Generator

C++ Constructors and Destructors MCQs
In C++, constructors and destructors are special member functions critical for the Resource Acquisition Is Initialization (RAII) paradigm and safe…
October 20, 2026By MCQs Generator

JavaScript Interview Questions MCQs
JavaScript interview questions evaluate a developer’s deep understanding of core language mechanics, execution models, and advanced runtime behavior. Top tech…
August 29, 2026By MCQs Generator
Related Categories

AI & Data Science MCQ
5 topics
By MCQs Generator

Arts & Humanities MCQ
4 topics
By MCQs Generator

Civil Engineering MCQ
4 topics
By MCQs Generator

Commerce & Business MCQ
4 topics
By MCQs Generator

Competitive Exams MCQ
5 topics
By MCQs Generator

Electrical & Electronics Engineering MCQ
3 topics
By MCQs Generator

General Knowledge MCQ
2 topics
By MCQs Generator

General Science MCQ
4 topics
By MCQs Generator

Law & Judiciary MCQ
3 topics
By MCQs Generator

Mechanical Engineering MCQ
4 topics
By MCQs Generator

Medical & Health Sciences MCQ
4 topics
By MCQs Generator

Modern Tech Fields MCQ
3 topics
By MCQs Generator