Question: There are two simple ways to traverse a list: using an iterator and using indexing and the get() method. For example the following two methods
There are two simple ways to traverse a list: using an iterator and using indexing and the get() method. For example the following two methods will produce the same output regardless of the dynamic type of the list passed in as a parameter:
public static
{
for (ListIterator
iterator.hasNext(); ) {
System.out.println(iterator.next());
}
}
public static
{
for (int i = 0; i < list.size(); ++i) {
System.out.println(list.get(i));
}
}
However, the claim is made that "printListOne" is more efficient for LinkedList than "printListTwo". Both algorithms perform the same for ArrayList objects, however. Provide an explanation for the two claims above.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
