When I pass this static method a linked list from main and remove the duplicates, the list remains un-changed. I assume this is because of some weird pass by value problem...Anyone know why?
public class LinkedListHelper{
public static <T> void eliminateDuplicates(LinkedList<T> list)
{
LinkedList<T> temp = new LinkedList<>();
temp.add(list.peekFirst()); //initialize this list with first element
ListIterator<T> itr1 = list.listIterator();
ListIterator<T> itr2 = temp.listIterator();
while(itr1.hasNext())
{
T element = itr1.next();
boolean found = false;
while(itr2.hasNext() && !found)
{
T current = itr2.next();
if(element == current)
found = true;
}
if(!found)
temp.add(element);
itr2 = temp.listIterator();
}
list = temp; //Why does this not work????
}
}