Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

There are two simple ways to traverse a list: using an iterator and using indexing and the get() method.

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 <E> void printListOne(List<E> list)

{

    for (ListIterator<E> iterator = list.listIterator();

            iterator.hasNext(); ) {

        System.out.println(iterator.next());

    }

}

public static <E> void printListTwo(List<E> list)

{

    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.

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question