title: Comparing two rows in a single 2D array
body: <p>I am trying to compare two rows that are in different order from a 2D array, and store elements that are the same from both rows. Here's an example of what I have produced:</p>
  
  <pre><code>String[] row1 = new String[10];
  String[] row2 = new String[10];
  String[][] fruit = {{"apple", "banana", "kiwi"},{"kiwi", "oranges", "grapes"}};
  
  for (int i = 0; i &lt; fruit.length; i++ ) {
      for (int j = 0; j &lt; fruit[i].length; j++){
              if(fruit[0][j].equals(fruit[1][j])) {
                  row1[j] = fruit[0][j];
                  row2[j] = fruit[1][j];
  
                  System.out.println("Match found");
              }else{
                  System.out.println("Not found"); 
              }
      }   
  }
  System.out.println("row1");
  System.out.println(Arrays.deepToString(row1));
  System.out.println("row2");
  System.out.println(Arrays.deepToString(row2));
  </code></pre>
  
  <p>I want the row1[] and row2[] to store the elements that are the same (which is kiwi in this example). However, the problem is .equals function only detects matching patterns. The example above only prints out nulls from row1 and row2.</p>
  
  <p>It should really print out:</p>
  
  <pre><code>row1
  [kiwi]
  row2
  [kiwi]
  </code></pre>
  
  <p>Note: I don't want to declare... <code>String check = "kiwi";</code> because the user can enter anything in the 2D array. </p>
  
  <p>Any suggestions? I feel I am getting close. I saw a similar example of someone using .equals and that worked, but it was only for single arrays.</p>