title: How to increment the size of an array within a loop
body: <p>I have this bubblesort code that i'm performing a runtime analysis on recording the time it takes to sort the array. I was wondering if there is any way i could increment the size of the array using a loop? Because at the moment i am incrementing it 100 at a time manually and i need to reach an array size of 5000.</p>
  
  <pre><code>public class BubbleSortworking{
  public static void main (String[] args) {
      Random rand = new Random();
      int myArray[] = new int[100];  //How to increment this using a loop
      int count, count2;
      count2 = 2;   //amount of times to run the loop
  
      //repeats the bubble sort, while also producing new arrays each time
      for (count = 0; count &lt; count2; count++){
          for (int i = 0; i &lt; myArray.length; i++){
  
              myArray[i] = rand.nextInt(100) + 1;  //produce numbers between 1 - ?
              //System.out.print(myArray[i] + ", ");   //displays unsorted array
          }
  
          bubble(myArray);
  
          // uncomment below 2 lines to prove each new sorted array cycle is unique 
          //for (int i = 0; i &lt; myArray.length; i++)
          //  System.out.print(myArray[i] + ", ");
      }
  }
  
  public static void bubble(int myArray[]){
      int temp;
      long start = System.nanoTime();
      //System.out.println("start " + start);
  
      //for (count = 0; count &lt; count2; count++){
      for (int i=0; i &lt; myArray.length - 1; i++) {
          for(int j=myArray.length - 1; j &gt; i; j--) {
              if (myArray[j] &lt; myArray[j-1]){
                  temp = myArray[j];
                  myArray[j] = myArray[j-1];
                  myArray[j-1] = temp;
              }
          }
      }
  
      long end = System.nanoTime();
      System.out.println(end - start);
      //System.out.println("elapsed time " + (end - start));
  
  
  }
  </code></pre>
  
  <p>}</p>