I'm working on a Linked List class and need a "removeAll" method that will iterate through a list remove each instance of x, then return a new list with these objects remove.
Code:
public void removeAll(T x) {
java.util.Iterator<T> it = this.iterator();
while(it.hasNext()) {
LinkedList l = new LinkedList();
T object = x;
l.remove(x);
System.out.println(it.next());
System.out.println(l);
}
}
In the main method, I've got this to add numbers to the list then remove each instance of 3.
Code:
ExtendedLinkedList<Integer> list3 = new ExtendedLinkedList<Integer>();
list3.add(3);
list3.add(4);
list3.add(6);
list3.add(3);
list3.add(9);
list3.removeAll(3);
I feel like I'm close, but the output I'm getting is the actual list, and an empty list.
3
[]
4
[]
6
[]
3
[]
9
[]