title: Compare 2D arrays with an array, and replacing matching elements
body: <p>Basically, I am trying to compare 2D arrays with an array, and if an element matches in single array with 2D array, the 2D array replaces the value of single array. I'll give an example:</p>
  
  <p>So, there are two 2D arrays:</p>
  
  <pre><code>arrayOne = [[livesAt, fname, city], [worksAt, fname, company]]
  arrayTwo = [[livesAt, x, y], [worksAt, x, z]]
  </code></pre>
  
  <p>And a single array:</p>
  
  <pre><code>findOut = [x,y,z]
  </code></pre>
  
  <p>The aim is arrayOne replaces everything in arrayTwo, and find out the elements in findOut array by comparing with arrayTwo.</p>
  
  <p><strong>Edit:</strong> The value of "x" reads the values of the location in the arrays... which is fname. So, the value of  "x" has to be the <strong>same</strong> from the first row and second row (fname).</p>
  
  <p>The answer should be:</p>
  
  <pre><code>arrayOne = [[livesAt, fname, city], [worksAt, fname, company]]
  arrayTwo = [[livesAt, fname, city], [worksAt, fname, company]]
  findOut = [fname,city,company]
  </code></pre>
  
  <p>I have attempted this in my code, like this:</p>
  
  <pre><code>for (int i = 0; i &lt; arrayOne.length;i++ ) {
          for (int j = 0; j &lt; arrayTwo.length; j++){
              for(int x = 0; x &lt; findOut.length;x++){
                  if(arrayTwo[i][j].equals(findOut[x])) {
                      arrayTwo[i] = arrayOne[i];
                      arrayTwo[j] = arrayOne[j];
                      findOut[x] = arrayOne[i][j];
  
                      System.out.println("Match found");
                  }else{
                      System.out.println("Not found");
                  }
          }
      }
  }
  </code></pre>
  
  <p>Most of it works except the findOut array only replaces the first element 'x' and not the others.</p>
  
  <blockquote>
    <p>[fname, y, z]</p>
  </blockquote>
  
  <p>And during the loop, it prints:</p>
  
  <pre><code>Not found
  Not found
  Not found
  Match found
  Not found
  Not found
  Not found
  Not found
  Not found
  Match found
  Not found
  Not found
  </code></pre>
  
  <p>I strongly feel there is a problem with my loop. Can anyone give me any pointers or suggestions on how to solve this? I have been trying to figure this out, but only made small progress.</p>