title: JAVA - How to find duplicate values in rows and columns in a 2D Array?
body: <p>I have a 2D Array and I would like to find an easier way to manipulate my code so that it will find if there is a duplicate in the column and easier way then what I have below:</p>
  
  <pre><code>for (int i=0; i &lt; array.length; i++) {
      for (int j=0; j &lt; array.length; j++) {
          for (int k=1; k &lt; array.length; k++){
              if (array[j+k][i] == array[j][i]) {
                 if (array[j][i] != 0) {
                  return true;
                 }
              }
          }
      } 
    }  
  return false;
  </code></pre>
  
  <p><strong>EDIT: KINDLY POINTED OUT THE ABOVE ^^ WON'T WORK EITHER AS IT WILL THROW AN OUT OF BOUNDS EXCEPTION</strong></p>
  
  <p>This way has too many loops and I am sure there must be an easier way to find duplicates rather than going through this massive looping process.</p>
  
  <p>This is for a square 2D array, ie. an array with rows = columns.</p>
  
  <p>If so, how can this new way work - and how can I manipulate it to work to find duplicate values in the rows as well.</p>
  
  <p>Thanks for the help.</p>