Thread: LinkedList help
View Single Post
Old 09-29-2008, 12:57 AM   PM User | #1
unc123w
New to the CF scene

 
Join Date: Sep 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
unc123w is an unknown quantity at this point
LinkedList help

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
[]
unc123w is offline   Reply With Quote