Recall & Review
beginner
What does the
length property of an array represent in Java?The
length property gives the total number of elements that the array can hold. It tells you how big the array is.touch_appClick to reveal answer
beginner
How do you access the length of an array named
numbers in Java?You use
numbers.length to get the number of elements in the array.touch_appClick to reveal answer
beginner
True or False: In Java,
length is a method for arrays.False. In Java,
length is a property (field) of arrays, not a method. So you do not use parentheses.touch_appClick to reveal answer
intermediate
What happens if you try to access an index equal to or greater than
array.length?You get an
ArrayIndexOutOfBoundsException error because array indexes start at 0 and go up to length - 1.touch_appClick to reveal answer
intermediate
Can the
length of an array be changed after the array is created in Java?No. The
length of an array is fixed once the array is created. To change size, you need to create a new array.touch_appClick to reveal answer
How do you get the number of elements in a Java array named
arr?What is the index of the last element in an array with length 10?
If you try to access
arr[arr.length], what happens?Can you change the size of an existing array in Java?
Which of these is correct to get the length of a Java array?
Explain how to find the number of elements in a Java array and why the
length property is important.Describe what happens if you try to access an array index outside the valid range using the
length property.