Multiple choice

What is the index of the last element of array list[]?

  1. list[list.length]

  2. list.length-1

  3. list[-1]

  4. list[list.length-1]

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The index of the last element in a Java array is always one less than the array's length, which is represented by 'list.length - 1'. Note that 'list[list.length - 1]' refers to the element itself, not its index.