title: Adding values to an array of undefined size
body: <p>I have researched and tried for hours to solve my problem, but the reality is that I can't find anything on it. It is simple really. I need to initialize java arrays of undefined size, and then compare the two. In the process of testing my program, when I have defined the array to a specific length (for example)</p>
  
  <pre><code>int[] array = new int[6];
  </code></pre>
  
  <p>the code waits until I have entered the six objects to move on to the next segment of code, because it is waiting for 6 integers as defined as the array length. But I can't define the array using </p>
  
  <pre><code>int[] array = {};
  </code></pre>
  
  <p>it obviously won't work, since array.length function will be 0. </p>
  
  <p>My code is below.</p>
  
  <pre><code>import java.util.Scanner;
  import java.util.Arrays;
  public class Test {
      public static void main(String[] args){
  
          Scanner input = new Scanner(System.in);
  
  
          // My problem is in the definition of the arrays or the for loops defining them below.
          int[] list1 = new int[]; // undefined
          int[] list2 = new int[]; // undefined
          // ask user to fill the two arrays to see if they are equal
          System.out.print("Enter list one &gt;&gt; ");
  
          for (int i = 0; i &lt; list1.length; i++){
              list1[i] = input.nextInt();
          }
  
          System.out.print("Enter list two &gt;&gt; ");
  
          for (int i = 0; i &lt; list2.length; i++){
              list2[i] = input.nextInt();
          }
  
  
          // call the equality testing method and output whether or not the two lists are strictly identical or not.
          if (equals(list1, list2) == true)
              System.out.println("The two lists are strictly identical");
          else
              System.out.println("The two lists are not strictly identical");
  
      }
  
      // this method 
      public static boolean equals(int[] list1, int[] list2){
          boolean bool = false;
          if (Arrays.equals(list1, list2))
              bool = true;
          else
              bool = false;
  
          return bool;
      }
  }
  </code></pre>