title: Looking for duplicate values in a 2 dimensional array
body: <p>The assignment I am working on requires that I create a Sudoku game without using any classes, methods, encapsulation, etc. I am having trouble validating that the values my user inputs into either my "fourArray" or "nineArray" contains no duplicate values. So far I have been trying to use a nested for-loop in order to iterate through both the columns and rows of either array. For example, I have been trying to include the following piece of code at the end of my program to determine if there are any duplicate values: </p>
  
  <pre><code>for (int i = 0; i &lt; fourArray.length; i++) {
      for (int j = i + 1; j &lt; fourArray.length; j++)
          if (fourArray[i] == fourArray[j]) {
              System.out.println("No Sudoku");
          } else {
              System.out.println("Sudoku!);
          }
   }
  </code></pre>
  
  <p>However this is not working. I want to iterate through the arrays to find any duplicate any values, and if there are none, then print out "Sudoku!" If there is any duplicate values, then I want to print out "Sudoku!" Do I need to sort the array at all? Or is there some method I am not aware of? I have included my program. Thank you for your time.</p>
  
  <pre><code>import java.util.Scanner;
  
  
  public class Sudoku {
  
      /**
       * @param args
       */
      public static void main(String[] args) {
          // TODO Auto-generated method stub
          int boardSize = -1;
          int[][] fourArray = { {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0} };
          int[][] nineArray = { {0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0} }; 
          while (true)
          {
              Scanner boardsizeOption = new Scanner(System.in);
              System.out.println("Please select a board size:" + "\n" + "1) 4x4" + "\n" + "2) 9x9");
              boardSize = boardsizeOption.nextInt();
              if (boardSize == 1 || boardSize == 2) {
                  break;
              }
          }
          if (boardSize == 1) { //still need to build complete board 
              int i, j = 0;
              for (i = 0; i &lt; fourArray.length; i++)
              {
                  for (j = 0; j &lt; fourArray.length; j++)
                      System.out.print(fourArray[i][j] + " ");
                  System.out.println();
              }
          } else if (boardSize == 2) { 
              int i, j = 0;
              for (i = 0; i &lt; nineArray.length; i++)
              {
                  for (j = 0; j &lt; nineArray.length; j++)
                      System.out.print(nineArray[i][j] + " ");
                  System.out.println();
              }
      }
          int dataSelection = -1;     
          while (true)
          {
              Scanner rowColumn = new Scanner(System.in);
              System.out.println("Please select which way you would like to enter the values:" + "\n" + "1) row" + "\n" + "2) columnn");
              dataSelection = rowColumn.nextInt();
              if (dataSelection == 1 || dataSelection == 2) {
                  break;
              }
          }
          //Entering by ROWS
          //This is for a 4x4 board size using rows
          if (dataSelection == 1) {
              if (boardSize == 1) {
                  int row = 1;
                  while (row &lt; 5) {
                      String row1Values4x4 = "-1";
                      while (true) {
                          Scanner firstRow4x4 = new Scanner(System.in);
                          System.out.println("Please enter four values using commas for row " + row); //this needs to loop
                          row1Values4x4 = firstRow4x4.next();
                          row1Values4x4 = row1Values4x4.replaceAll(" ",""); //this is in case user enters numbers with spaces
                          if (row1Values4x4.length() == 7) {
                              break;
                          }
                      }
                      String strArray[] = row1Values4x4.split(",");
                      int arraySidesInteger[] = new int[strArray.length];
                      for (int i = 0;  i &lt; strArray.length;  i++) {
                          arraySidesInteger[i] = Integer.parseInt(strArray[i]);
                      }
                      fourArray[row-1] = arraySidesInteger;
                      for (int i = 0; i &lt; fourArray.length; i++) {
                          for (int j = 0; j &lt; fourArray.length; j++)
                              System.out.print(fourArray[i][j] + " ");
                          System.out.println();
                      }
                      row++;
                  }
                  //This is for a 9x9 board size using rows 
                  } else { 
                      int row = 1;
                      while (row &lt; 10) {
                          String row1Values9x9 = "-1";
                          while (true) {
                              Scanner firstRow9x9 = new Scanner(System.in);
                              System.out.println("Please enter nine values using commas for row " + row); //this needs to loop
                              row1Values9x9 = firstRow9x9.next();
                              row1Values9x9 = row1Values9x9.replaceAll(" ",""); //this is in case user enters numbers with spaces
                              if (row1Values9x9.length() == 17) {
                                  break;
                              }
                          }
                          String strArray[] = row1Values9x9.split(",");
                          int arraySidesInteger[] = new int[strArray.length];
                          for (int i = 0;  i &lt; strArray.length;  i++) {
                              arraySidesInteger[i] = Integer.parseInt(strArray[i]);
                          }
                          nineArray[row-1] = arraySidesInteger;
                          for (int i = 0; i &lt; nineArray.length; i++) {
                              for (int j = 0; j &lt; nineArray.length; j++)
                                  System.out.print(nineArray[i][j] + " ");
                              System.out.println();
                          }
                          row++;
                      }
                  }
              //Entering by COLUMNS
              //This is for 4x4 board size using columns 
              } else { 
                  if (boardSize == 1) {
                      int column = 1;
                      while (column &lt; 5) {
                          String column1Values4x4 = "-1"; 
                          while (true) {
                              Scanner firstColumn4x4 = new Scanner(System.in);
                              System.out.println("Please enter four values using commas for column " + column);
                              column1Values4x4 = firstColumn4x4.next();
                              column1Values4x4 = column1Values4x4.replaceAll(" ","");
                              if (column1Values4x4.length() == 7) {
                                  break;
                              }
                          }
                          String strArray[] = column1Values4x4.split(",");
                          int arraySidesInteger[] = new int[strArray.length];
                          for (int i = 0;  i &lt; strArray.length;  i++) {
                              arraySidesInteger[i] = Integer.parseInt(strArray[i]);
                          }
                          for (int i = 0; i &lt; arraySidesInteger.length; i++) {
                              fourArray[i][column-1] = arraySidesInteger[i];
                          }
                          for (int i = 0; i &lt; fourArray.length; i++) {
                              for (int j = 0; j &lt; fourArray.length; j++)
                                  System.out.print(fourArray[i][j] + " ");
                              System.out.println();
                          }
                          column++;
                      }
                  //This is for a 9x9 board size using columns
                  } else { 
                      int column = 1;
                      while (column &lt; 10) {
                          String column1Values9x9 = "-1";
                          while (true) {
                              Scanner firstColumn9x9 = new Scanner(System.in);
                              System.out.println("Please enter nine values using commas for column " + column);
                              column1Values9x9 = firstColumn9x9.next();
                              column1Values9x9 = column1Values9x9.replaceAll(" ","");
                              //row1Values4x4 = row1Values4x4.replaceAll(",","");
                              if (column1Values9x9.length() == 17) {
                                  break;
                              }
                          }
                          String strArray[] = column1Values9x9.split(",");
                          int arraySidesInteger[] = new int[strArray.length];
                          for (int i = 0;  i &lt; strArray.length;  i++) {
                              arraySidesInteger[i] = Integer.parseInt(strArray[i]);
                          }
                          for (int i = 0; i &lt; arraySidesInteger.length; i++) {
                              nineArray[i][column-1] = arraySidesInteger[i];
                          }
                          for (int i = 0; i &lt; nineArray.length; i++) {
                              for (int j = 0; j &lt; nineArray.length; j++)
                                  System.out.print(nineArray[i][j] + " ");
  
  
                      System.out.println();
                      }
                      column++;
                  }
              }
              for (int i = 0; i &lt; fourArray.length; i++) {
                  for(int j = i + 1; j &lt; fourArray.length; j++) {
                      if(fourArray[i] == fourArray[j]) {
                          System.out.println("No Sudoku");
                      } else {
                          System.out.println("Sudoku!");
                      }
              }
          }
      }
  }
  </code></pre>