Solved

Looping through 2 lists

Posted on 2013-06-24
3
225 Views
Last Modified: 2013-07-10
Looping through two Lists and pass Lista object  and  Listb object to a calling method
 when a matching code is found in listb
Once a match is found, stop processing list b and return to lista and loop
loop through list B until a match is found.

Is this how I loop through two lists?
How do I stop the looping in the second loop when a match is found?
I do not want to pass a list to the called method, but pass the
object as I loop trough. How do I pass both lista and listb objects?

public getMatching Code (List <itemVO) lIstA,  List(ItemVO) listB

for itemVO voA : listA
{
 for item  voB : listB
   {  
   if listb.getCode = lista.getCode
      {
       Do I use voA and voB to pass to the method?
       calculateDiff (voA, VoB)
       Exit this loop and get the next value
       in the first loop and then reenter this loop
       how do I stop this loop and go back to the first loop and re-enter this loop

      }
   }
}
0
Comment
Question by:cookiejar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Expert Comment

by:gudii9
ID: 39273564
>>> if listb.getCode = lista.getCode


are you sure you want to use =.
0
 
LVL 36

Expert Comment

by:mccarl
ID: 39273627
To exit that inner loop, you need to use the...

break;

...statement.
0
 
LVL 16

Accepted Solution

by:
Valeri earned 500 total points
ID: 39273976
public void getMatchingCode(List<String> ListA, List<String> ListB) {
        for (ItemVO itemA : ListA) {
            for (ItemVO itemB : ListB) {
                if (itemA.equals(itemB)) {
                    calculateDiff(itemA, itemB);
                    break;
                }
            }
        }
    }
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question