Limited access

Upgrade to access all content for this subject

When would the following method result in a NullPointerException?

// Count the number of words that contain a lowercase Z
public static int countWordsWithZ(ArrayList<String> words)
    int count=0;
    for (String word : words)
        if (word.indexOf("z")>=0)
    return count;
  I. When an array list that is not instantiated is passed as a parameter
 II. When the array list being passed as the parameter contains a null element
III. When an empty array list is passed as a parameter
 IV. When an array list containing Integer objects is passed as a parameter

I and II only.


I and III only.


II and III only.


I, II, and IV only.


II, III, and IV only.

Select an assignment template