Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 27 of 27

Thread: It does not return data as it should in the cycle

  1. #26
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: It does not return data as it should in the cycle

    Is this what you want to do:
    Compare one item from the first list against all the items in the second list
    If that item from the first list is not found after looking at all the items in the second list, then print a message

    To do that you need to use a boolean variable, for example: matchFound that is initialized to false.
    Then search the for one item from the first list against all the items in the second list.
    If a match is found, the set matchFound to true.
    After the end of the search loop, if matchFound is false, then print a message saying no match was found
    For example:
      for (Item1 item1 : firstList) {
        boolean matchFound = false;
        for(Item2 item2 : secondList) {
          if(item1 == item2) {
              matchFound = true;  // remember 
          }
        }
        if(!matchFound) {
          print item1 not found in secondList
        }
      }
    If you don't understand my answer, don't ignore it, ask a question.

  2. #27
    Member
    Join Date
    Jun 2017
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: It does not return data as it should in the cycle

    exact. Thank you very much and above all that you helped me. This forum is exceptional

Page 2 of 2 FirstFirst 12

Similar Threads

  1. String subdivision and data return problem
    By glprobot in forum Java Theory & Questions
    Replies: 1
    Last Post: May 31st, 2019, 06:29 AM
  2. Two ArrayLists don't cycle thru formula
    By CiscoKid in forum Loops & Control Statements
    Replies: 1
    Last Post: January 2nd, 2019, 06:41 AM
  3. Replies: 8
    Last Post: December 4th, 2012, 04:58 AM
  4. [SOLVED] Problem accessing specific data in an array and getting it to return properly
    By Universalsoldja in forum Collections and Generics
    Replies: 3
    Last Post: February 4th, 2010, 04:26 PM