Recall & Review
beginner
What is the syntax to declare and initialize an array of integers with values 1, 2, 3 in Java?
You can declare and initialize an integer array like this:
int[] numbers = {1, 2, 3};touch_appClick to reveal answer
beginner
How do you find the length of an array named
arr in Java?Use
Example:
arr.length to get the number of elements in the array.Example:
int size = arr.length;
touch_appClick to reveal answer
beginner
How can you loop through all elements of an array
arr using a for-each loop?Use the for-each loop syntax:
This goes through each item in
for (int element : arr) {
// use element
}This goes through each item in
arr one by one.touch_appClick to reveal answer
intermediate
How do you copy an array
source to a new array copy in Java?You can use
This creates a new array with the same elements.
Arrays.copyOf:int[] copy = Arrays.copyOf(source, source.length);
This creates a new array with the same elements.
touch_appClick to reveal answer
beginner
How do you sort an array
arr of integers in Java?Use
Example:
Arrays.sort(arr); to sort the array in ascending order.Example:
Arrays.sort(arr);
touch_appClick to reveal answer
Which of the following is the correct way to declare an array of strings named
names?How do you access the third element of an array
arr?What does
arr.length return?Which method sorts an array
arr in Java?How do you loop through all elements of an array
arr using a for-each loop?Explain how to declare, initialize, and access elements in a Java array.
Describe how to loop through all elements of an array and how to sort an array in Java.
