Arrays Flashcards
A ________________ is a way of organizing and storing data so that it can be accessed and modified efficiently
data structure
Arrays in Java are _______________ data structures, meaning they store elements of the same data type.
homogeneous
A specific element in an array is accessed by its _________. In Java, array indices start from __
index, 0
When an array is created, Java allocates a continuous __________________ to store its values
block of memory
The ______________ is the total number of elements stored in an array, and in Java, you can get this using _____________
array length, .length
A one-dimensional array can be visualized as a _____.
row
During array construction, each element is initialized to a _________ value through a process called _________________.
default, auto-initialization
TRUE or FALSE
You cannot directly initialize only part of an array in Java.
TRUE
A common loop used for traversing arrays and accessing each element one by one is the __________.
for loop
The enhanced for loop, also called the _______, simplifies array traversal without needing indices
for-each loop
TRUE or FALSE
You can modify array elements using for-each loop
FALSE
Trying to access an index outside the valid range of an array will cause an _______________________________.
ArrayIndexOutOfBoundsException
TRUE or FALSE
Once an array is created, its size cannot be changed
TRUE
___________ is used if dynamuc resizing is needed.
ArrayList
TRUE or FALSE
The Arrays class provides non-static methods to perform common array operations
FALSE, static
The Arrays.sort() method sorts an array in _________________.
ascending order
The Arrays.equals() method checks if two arrays contain the same ___________ in the same ________.
elements, order
Which of the following is NOT a limitation of arrays in Java according to the provided text?
a) Fixed size limitation
b) Inefficient for insertions/deletions
c) Requires manual sorting/searching
d) Can automatically resize
d) Can automatically resize
What is the index of the first element in a Java array?
a) 1
b) 0
c) -1
d) The array’s length
b) 0
What is the default value assigned to elements of a boolean array upon initialization?
a) true
b) false
c) null
d) 0
b) false
Which method from the Arrays class is used to create a new array with the same elements as an original array?
a) Arrays.fill()
b) Arrays.toString()
c) Arrays.copyOf()
d) Arrays.sort()
c) Arrays.copyOf()
Which type of loop is best suited for modifying elements within an array?
a) Enhanced for loop (for-each)
b) while loop
c) Traditional for loop
d) do-while loop
c) Traditional for loop
The position of an element inside an array; in Java, it starts from 0.
Index
A runtime error that occurs when trying to access an array element at an invalid position.
ArrayIndexOutOfBoundsException
A data structure that stores one or more values of a specific data type under a single variable name, providing indexed access.
Array
The process where each element in an array is assigned a default value when the array is created.
Auto-initialization
A Java utility class that provides static methods for common array operations like sorting, searching, and copying.
Arrays class
A loop construct that allows you to iterate through an array without explicitly managing indices, primarily used for read-only access.
Enhanced for loop (for-each)
The property of an array that represents the total number of elements it can hold.
Array length
A type of array that can be visualized as a row of elements.
Single Dimensional Array (1D Array)
A method used to search for an element in a sorted array efficiently, often returning a negative value if the element is not found.
Arrays.binarySearch()