1 Reply Latest reply on May 16, 2003 12:13 PM by cepage

    Iterating a collection returned via cmr

    sysuser1

      Hi,

      I have 2 records in the database A,B,C.

      java.util.Collection col = getCmpChild(); - Here getcmpchild() is a cmr that returns a collection.

      When i print out the first object in the collection i get
      its value as C instead of A.

      (
      Iterator itr = col.iterator();
      Object obj = itr.next();
      SampleCMPChild child = (SampleCMPChild)obj;
      System.out.println("Obj after cast -"+child.getLocation());

      Also when we iterate the collection in a while loop it prints out c,c and c, whereas the expected result would be A,B and C.

      java.util.Collection col = getCmpChild();


      Iterator itr = col.iterator();


      while(itr.hasNext())
      {
      Object obj = itr.next();
      SampleCMPChild child = (SampleCMPChild)obj;
      System.out.println("Obj after cast - "+child.getLocation());
      System.out.println("Child handlde - "+child);
      al.add(child);
      }
      Any help in this regard will be sincerely appreciated.

      Thks