First, this list is for Struts issues, not a general Java programming help. That said, here's a quick response:

Modifying an Iterator while iterating it is not guaranteed to work. It depends on the specific Iterator implementation. This is clearly documented in the Javadoc for the Collections APIs, so read those to find out if what you are doing is safe.

The general solution would be to take a copy of the iterator, iterate the copy and modify the original (or vica versa).

L.

temp temp wrote:
    How can I  iterate  a collection  and modify at the same time ?
      Example
      public static Collection  getAncestors(
  Entity aEntity, Object aContext ){
         Collection vAncestors=new ArrayList();
                  IDocument vDocument= findDocumentByName(
  aEntity.getSuper(),  aContext);
         vAncestors.add(vDocument);
      for(
  Iterator  i=vAncestors.iterator();
i.hasNext(); ){ getAncestors(vAncestors, (IDocument)i.next(), aContext); } return vAncestors;
  }
public static void getAncestors( Collection aAncestors, IDocument aDocument , Object aContext){
         Entity  vEntity=(Entity)aDocument.get();
         if(vEntity.getSuper()!=null){
           IDocument vDocument=    findDocumentByName(
vEntity.getSuper(), aContext);
       aAncestors.add(vDocument);
} } Thanks Miro ---------------------------------
Sucker-punch spam with award-winning protection.
 Try the free Yahoo! Mail Beta.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to