Results 1 to 2 of 2

Thread: Iterations

  1. #1
    Join Date
    Oct 2003

    Unhappy Unanswered: Iterations

    I have two iterations. I'm not sure if this is correct, but what I'm trying to do is go through one of them, when I find a match, I do a merge. But if they don't match, I still want to loop through the second iteration. If they two id's that I'm matching never match, then I want to move to the next record of the first iteration. What is the best way to do this? Currently I have this:

    ListIterator cpIterator = completionProfiles.listIterator();
    ListIterator tasksIterator = tasks.listIterator();

    //Merge Tasks with CompletionProfiles
    try {
    CompletionProfile currentCP = (CompletionProfile);
    while(tasksIterator.hasNext()) {
    Task currentTask = (Task);
    if(currentTask.equals(currentCP)) {
    if(currentCP.isActiveInd()) {
    } else {
    currentCP = (CompletionProfile);

    } catch(NoSuchElementException nsee) {
    //No further merging necessary.
    //Merging complete.
    return true;

    Any help would be appreciated.


  2. #2
    Join Date
    Apr 2005
    Baltimore, MD
    You need to use two loops.
    for (Iterator iter1 = collection1.iterator(); iter1.hasNext();) {
        Object obj1 =;
        for (Iterator iter2 = collection2.iterator(); iter2.hasNext();) {
            Object obj2 =;
            if (some condition) {
                //do something;
    Depending on what type of collection you are using, you should also be able to use:
    That will make collection1 the intersection of the 2 collections.
    Give a man a fish and you feed him for a day. Teach a man to fish and you lose a steady customer.
    Eclectic Web Development (under heavy construction)

Posting Permissions

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