Array Basics in AP Computer Science A
Which statement correctly initializes an array of type boolean
named flags
with the elements true
, false
, and true
in that order?
boolean[] flags = {true, false, true};
boolean[] flags = new boolean[3] {true, false, true};
boolean flags = new boolean[3] {true, false, true};
boolean flags = {true, false, true};
How do you find the length of the array myArray
in Java?
sizeOf(myArray)
myArray.length()
myArray.size()
myArray.length
What is the correct way to access the last element in an array named data
?
data[data.length + 1]
data[data.length] - 1
data[data.length]
data[data.length - 1]
How are items in arrays separated in Java?
Using semicolons
Using periods
Using commas
Using colons
What is the default value of an element in a primitive boolean array?
0
false
true
null
How do you access the first element in an array named values
?
values.first()
values[-1]
values[0]
values[1]
How do you access the second-to-last element in an array named data
?
data[data.length]
data[data.length + 1]
data[data.length - 1]
data[data.length - 2]

How are we doing?
Give us your feedback and let us know how we can improve
What is the initial value of a primitive double array element?
0.0
false
null
-1
Which statement correctly initializes an array of type double
with 5 elements?
double arr = {5};
double[] arr = {5};
double[] arr = new double[5];
double arr = new double[5];
How do you initialize an array of Strings with 3 elements of default value null
?
String[] arr = new String{"a", "b", "c"};
String[] arr = {"a", "b", "c"};
String[] arr = new String[3];
String[3] arr = new String[];