title: Experiment controller using a generic array and method
body: <p>I am trying to find the time it takes for a Bubble sort method of sorting an integer array vs a selection sort.</p>
  <pre><code>public class ExperimentController
  {
      private static int[] intArray = {};
      
  
       public static void main(String[] args)
      {
        System.out.println(&quot;&quot;);
        ExperimentController EX = new ExperimentController();
  
        for(int i =0; i&lt;=300;i=i+50){
            long time = EX.timeBubbleSortPerformance(i, 0);
            System.out.println(time);
  
          }
          
          
         }
         
      public long timeBubbleSortPerformance(int numberOfItems, int seed){
          
          long startTime = System.nanoTime();
          RandomStuffContainer RSC = new RandomStuffContainer();
          Random random = new Random(seed);
          for(int i=0; i&lt;numberOfItems; i++){
              int randomInt = random.nextInt();
              RSC.addToFront(intArray[randomInt]);   
              RSC.selectionSort(intArray[randomInt]);   
  
          }
          
          
          
          long stopTime = System.nanoTime();
          long timeTotal = stopTime-startTime;
          return timeTotal;
      }
  }
  </code></pre>
  <p>The method calls the Random stuff container class for the methods.</p>
  <pre><code>public class RandomStuffContainer&lt;T extends Comparable&lt;T&gt;&gt;
  {
         ArrayList&lt;T&gt; array = new ArrayList&lt;T&gt;();
  
      public  void main(String[] args){
       ArrayList&lt;T&gt; array = new ArrayList&lt;T&gt;();
  
          
      }
      
      public void addToFront(T value)
      {
         array.add(0, value);
      }
      
      /**
       * Adds the inputted String i to the back of the Arraylist
       *
       * @param  A generic parameter T
       */
      public void addToBack(T value)
      {
         array.add(value);
      }
      
      
      /**
       * Sorts the Arraylist using selection sort algorithim
       *
       */
      public void selectionSort() 
      {
         for(int i=0; i&lt;array.size() -1; i++)
      {
          int smallestIndex = i;
  
          for(int j=i+1; j&lt;array.size(); j++)
          {
              if(array.get(smallestIndex).compareTo((array.get(j))) &gt; 0  )
              {
                  smallestIndex = j;
              }
          }
          T temp = array.get(i);
          array.add(i,array.get(smallestIndex));
          array.add(smallestIndex, temp);
      } 
  }
      
  
      
      public void bubbleSort(){
           T temp;
           
          if (array.size()&gt;1) // check if the number of orders is larger than 1
          {
              for (int x=0; x&lt;array.size(); x++) // bubble sort outer loop
              {
                  for (int i=0; i &lt; array.size()-i; i++) {
                      if (array.get(i).compareTo(array.get(i+1)) &gt; 0)
                      {
                          temp = array.get(i);
                          array.set(i,array.get(i+1) );
                          array.set(i+1, temp);
                      }
                  }
              }
          }
      }
      
      /**
       * Copies array list data to String and returns String.
       * Used for testing
       */
      public String toString() {
         {
          StringBuilder sb = new StringBuilder();
          for (T s : array)
          {
              sb.append(s.toString());
              sb.append(&quot;\t&quot;);
          }      
          return  sb.toString();
      }
   }
  }
  </code></pre>
  <p>I am trying to use random to randomly fill the array in RandomStuffContainer with ints and then use the sort method to sort that and get the runtime from it. I know my code is messy and sorry for that but any help would be very much appreciated.</p>