Multiple choice

How do you get the size of an array?

  1. myArray.size

  2. myArray.size()

  3. myArray.length

  4. myArray.length()

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

In Java, arrays are objects that expose a public, final field named 'length' to store the number of elements. Because it is a field and not a method, you access it without parentheses, unlike the length() method used for Strings or the size() method used for Collections.