43.4k views
5 votes
Assuming list is a LinkedList of String objects that contains the following: [A, B, C, D, E, F].

list.indexOf( (4)) would return ""E"".
True
False

User Tim Holt
by
8.5k points

1 Answer

2 votes

Final answer:

The claim is false. The correct method to obtain the element at the fourth index, which is "E", from a LinkedList is list.get(4), not list.indexOf((4)), which takes an object and returns its index.

Step-by-step explanation:

The statement that list.indexOf((4)) would return "E" is False. When working with a LinkedList of String objects in Java, the indexOf() method takes an object as an argument and returns the index of the first occurrence of that object in the list. Since the list indices start at 0, calling indexOf(4) would not make sense because 4 is an integer, not a String object from the list. If you would like to get the item at the 4th index, which is "E", you should use the get() method with list.get(4).