interators problems
Trace the method addToList() that inserts a new item into a list.
public static <T> void addToList(LinkedList<T> list, T item)
{
Iterator<T> iter = list.iterator();
while (iter.hasNext())
if (item.equals(iter.next()))
return;
list.add(item);
}
A) Consider the empty LinkedList intList and the Integer array arr.
LinkedList<Integer> intList = new LinkedList<Integer>();
Integer[] arr = {5, 2, 4, 5, 7, 2};
What are the elements in intList after executing the loop?
for(int i=0; i<arr.length; i++)
addToList(intList, arr);
B) Assume LinkedList charList is an empty collection of Character type and string str = "mississippi". What are the elements in charList after executing the loop?
for (int i =0; i><str.length(); i++)
addToList(charList, str.charAt(i));>

