Java OCA OCP Practice Question 2732

Question

Given the following code, which of the following statements can be used to determine if cat can be found in the list?

ArrayList<String> list = new ArrayList<>();
list.add("dog");
list.add("cat");
list.add("frog");
a.   list.contains("cat")
b.   list.hasObject("cat")
c.   list.indexOf("cat")
d.   list.indexOf(1)


a and c

Note

The contains method will return true if the object is found and indexOf takes an object reference and returns the index of the object if found, otherwise it returns a -1.

The indexOf method does not take an integer argument and the hasObject() method does not exist.




PreviousNext

Related