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

(""C"") would fetch the index of the first occurrence of ""C"" in the linked list.
True
False

1 Answer

3 votes

Final answer:

The statement is true; calling indexOf("C") on a LinkedList containing [A, B, C, D, E, F] would return 2, the index of the first occurrence of "C".

Step-by-step explanation:

The statement in the question implies the use of a method that retrieves the index of an element within a LinkedList. In Java, for instance, this can be accomplished using the indexOf() method. If the LinkedList contains the elements [A, B, C, D, E, F], then calling indexOf("C") would indeed return the index of the first occurrence of "C" in the list. Since "C" is the third element in the list, and given that indices in Java are zero-based, the method would return 2 as the index of "C".

User Dean Johnson
by
8.6k points