Results 1 to 3 of 3
Thread: List Iterator
- 05-10-2012, 12:02 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 55
- Rep Power
- 0
List Iterator
Hi all,
The remove method is not working in my List iterator code. below mentioned is the code.
import java.util.*;
class Listi
{
public static void main(String[] args)
{
ArrayList <Integer> ai = new ArrayList<Integer>();
ai.add(9);
ai.add(0);
ai.add(8);
ListIterator li = ai.listIterator();
while(li.hasNext())
{
String o = (String)li.next();
if(o.equals("9"))
{
li.remove();
}
System.out.println(o);
}
}
}
Now when i run the above code i get class cast exception. Kindly help!!
Thank you
- 05-10-2012, 12:13 PM #2
- 05-10-2012, 12:37 PM #3
Member
- Join Date
- Jan 2012
- Posts
- 55
- Rep Power
- 0
Similar Threads
-
Linked List: Removing Largest Element Using Iterator
By helloworld12 in forum New To JavaReplies: 2Last Post: 05-08-2011, 05:28 AM -
linked list iterator
By TopNFalvors in forum New To JavaReplies: 3Last Post: 03-31-2011, 03:03 AM -
Which would be better List iterator or accessing through index?
By deepuhassan in forum Advanced JavaReplies: 2Last Post: 12-17-2009, 03:06 PM -
[SOLVED] Writing an Iterator method in a custom list
By xcallmejudasx in forum New To JavaReplies: 2Last Post: 02-12-2009, 05:22 AM -
Creating an Iterator for Linked List
By spanky in forum New To JavaReplies: 3Last Post: 10-05-2008, 07:16 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks