Hi,

Can anyone tell me what is the problem with the below code:

String eleSrc=srcEle.toString();
      String srcdata_list[]=eleSrc.split("-");
      String eleDest=destEle.toString();
      String destdata_list[]=eleDest.split("-");
      int found=0;
      for(int i=0;i<srcdata_list.length;i++)
      {
         for(int j=0;j<destdata_list.length;i++)
         {
            if(srcdata_list[i].equals(destdata_list[j]))
            {
               found++;
               System.out.println("matches");
               System.out.println("after matches");
               break;
            }
            else
            {
               System.out.println("in else");
               
            }
         }
         System.out.println("out of first for lopp");
        if(found==0)
        {
           System.out.println("Not found..appending to list");
           missingEle.append(srcdata_list[i]);
        }
            
      }

It prints the following O/P:


matches
after matches
out of first for lopp
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else
in else


Why is it not going out of the first for loop????

Recommended Answers

All 3 Replies

Line 8 increments i, should be j?

Line 8 increments i, should be j?

Thanks James, It's working now but now I/m stuck with another problem. :(

If the contents in the array srcdata_list is not found in destdata_list, then that content should be appended to the string buffer(from line 24).

Why is not?? Anu idea??

Hey I got it !!!
guess it was a rookie mistake.
Posting the correct code.

String eleSrc=srcEle.toString();
      String srcdata_list[]=eleSrc.split("-");
      String eleDest=destEle.toString();
      String destdata_list[]=eleDest.split("-");
      int found=0;
      
      for(int i=0;i<srcdata_list.length;i++)
      {
         done:for(int j=0;j<destdata_list.length;j++)
         {
            if(srcdata_list[i].equals(destdata_list[j]))
            {
               found++;
               System.out.println("matches");
               break done;
            }
            else
            {
               found=0;//this was missing
               System.out.println("in else");
               
            }
         }
         System.out.println("found= "+found);
         System.out.println("out of first for lopp");
        if(found==0)
        {
           System.out.println("Not found..appending to list");
           countMatches(1);
           missingEle.append(srcdata_list[i]);
        }
            
      }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.