Results 1 to 3 of 3

Thread: List Iterator

  1. #1
    java4amanda is offline Member
    Join Date
    Jan 2012
    Posts
    55
    Rep Power
    0

    Default 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

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: List Iterator

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    java4amanda is offline Member
    Join Date
    Jan 2012
    Posts
    55
    Rep Power
    0

Similar Threads

  1. Linked List: Removing Largest Element Using Iterator
    By helloworld12 in forum New To Java
    Replies: 2
    Last Post: 05-08-2011, 05:28 AM
  2. linked list iterator
    By TopNFalvors in forum New To Java
    Replies: 3
    Last Post: 03-31-2011, 03:03 AM
  3. Replies: 2
    Last Post: 12-17-2009, 03:06 PM
  4. [SOLVED] Writing an Iterator method in a custom list
    By xcallmejudasx in forum New To Java
    Replies: 2
    Last Post: 02-12-2009, 05:22 AM
  5. Creating an Iterator for Linked List
    By spanky in forum New To Java
    Replies: 3
    Last Post: 10-05-2008, 07:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •