title: Searching duplicate entries in JTable depending on multiple columns
body: <p>Im still very new to java and just learned to work with JTables. When checking for duplicates in a JTable, I used this method for checking only one Column for my keyword:</p>
  
  <pre><code>private boolean duplicateEntry(String entry, JTable table, int column)
  {       
      System.out.print("Duplicate check for "+entry+"...");
      for (int i = 0; i &lt; table.getRowCount(); i++)
      {
          String found = table.getValueAt(i, column).toString();
          if (found.equals(entry))
          {
              System.out.println(" already in db!");
              return true;
          }
      }
      System.out.println("no entry found!");
      return false;
  }
  </code></pre>
  
  <p>I'm now trying to get it to work for a more complex duplicate check: I want to check if the found row is identical in every column. To make it more clear the table looks like this:</p>
  
  <p>| firstname | lastname | nationality | state |</p>
  
  <hr>
  
  <p>If this is is my existing entry:</p>
  
  <p>| John | Smith | German | Texas |</p>
  
  <p>I want my duplicate check to return only true if all columns of the new row have the same values as the existing one.</p>
  
  <hr>
  
  <p>So if wanted to add | John | Smith | <strong>Polish</strong> | Texas | -> check should return <strong>false</strong></p>
  
  <hr>
  
  <p>So if wanted to add | John | Smith | German | Texas | -> check should return <strong>true</strong></p>
  
  <hr>
  
  <p>I got it working with the following code, but it feels sloppy and inefficient:</p>
  
  <p><em>hCol</em> is the index of the table's column</p>
  
  <pre><code>priavte boolean duplicateEntryComplex(JTable table, String vMatch, int vCol, ArrayList&lt;String&gt; hMatch, int[] hCol)
  {
      //search for matching rows (vertical)
      System.out.print("Duplicate check for "+vMatch+"...");
  
      for (int i = 0; i &lt; table.getRowCount(); i++)
      {
          String found = table.getValueAt(i, vCol).toString();
          if (found.contains(vMatch))
          {
              // search inside found row (horizontal)
              int cols = hCol.length;
              ArrayList&lt;Boolean&gt; check = new ArrayList&lt;Boolean&gt;();                
              for (int r = 0; r &lt; cols; r++)
              {
                  boolean match = false;
                  String searchFor2 = hMatch.get(r);
                  String found2 = table.getValueAt(i, hCol[r]).toString();
                  if (found2.contains(searchFor2))
                  {
                      match = true;
                  }
                  // add result for current column to ArrayList
                  check.add(match);                   
              }
              for (int x= 0; x &lt; check.size(); x++)
              {
                  if (check.get(x) == false)
                  {
                      break;
                  }
                  if (x == check.size()-1) // if all field were identical
                  {
                      System.out.println(" already in db!");
                      return true;
                  }
              }               
          }
      }
      System.out.println(" no duplicates found!");
      return false;
  }
  </code></pre>
  
  <p>So my question is, if there is a more correct and efficient way to do this.</p>