Challenge for ArrayList Methods and Docs

Challenge

It can be confusing to remember the different names Java uses. ArrayList uses the method size() for the number of items in it, while String uses the method length() for its number of characters, and arrays use a final field called length for the number of items it can hold.

You can review this in the code below. Which line of code will cause a compile error?

int[] nums = new int[5];  // Line 0
ArrayList<String> words = new ArrayList<String>();  //1
String word = "hello";  //2
int l = word.length;  //3
int s = words.size(); //4
int n = nums.length; //5

Please sign in or sign up to submit answers.

Alternatively, you can try out Learneroo before signing up.

Contact Us
Sign in or email us at [email protected]