Results 1 to 3 of 3

Thread: Vector problem

  1. #1
    mharsijamel is offline Member
    Join Date
    Aug 2011
    Posts
    60
    Rep Power
    0

    Default Vector problem

    Java Code:
    Vector v1=new Vector();
    v1.add("A");
    Iterator k = v1.iterator();
    while(k.hasNext())
            {
                String sreq=(String) k.next();
                Vector h=children(sreq);
                Iterator k1 = h.iterator();
                while(k1.hasNext())
                {
                    String s2=(String) k1.next();
                    v1.add(s2);
                }
            }
    this code cause this error "java.util.concurrentmodificationexception"
    so how could i fix this error?

  2. #2
    Iron Lion is offline Senior Member
    Join Date
    Nov 2010
    Posts
    210
    Rep Power
    4

    Default Re: Vector problem

    From the API:
    The Iterators returned by Vector's iterator and listIterator methods are fail-fast: if the Vector is structurally modified at any time after the Iterator is created, in any way except through the Iterator's own remove or add methods, the Iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the Iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future. The Enumerations returned by Vector's elements method are not fail-fast.
    Try using the add method of the Iterator. Or could you just use an ArrayList instead of a Vector?

  3. #3
    mharsijamel is offline Member
    Join Date
    Aug 2011
    Posts
    60
    Rep Power
    0

    Default Re: Vector problem

    many thanks i used ListIterator and it succeed

Similar Threads

  1. Vector Problem
    By osmaavenro in forum New To Java
    Replies: 14
    Last Post: 10-01-2010, 11:03 AM
  2. vector problem
    By shinichi90 in forum New To Java
    Replies: 9
    Last Post: 08-30-2010, 08:25 PM
  3. Problem with Vector
    By banhbaochay in forum New To Java
    Replies: 9
    Last Post: 04-01-2010, 05:01 PM
  4. Vector problem
    By Ace_Of_John in forum New To Java
    Replies: 1
    Last Post: 01-27-2008, 08:53 PM
  5. vector problem
    By mambo_jumbo in forum New To Java
    Replies: 1
    Last Post: 11-17-2007, 10:44 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
  •