Solved

Looping through 2 lists

Posted on 2013-06-24
3
208 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
3 Comments
 
LVL 7

Expert Comment

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


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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PDFBox - convert image to PDF, PDF resolution 3 117
xampp tool 12 25
difference of if loops 23 41
tomcat not starting 6 30
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

910 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now