title: Basic Bubble Sort with ArrayList in Java
body: <p>I was implementing a comparator, and it wasn't working, so I thought I'd write a basic bubble sort.</p>
  
  <pre><code>int[] numbers = { 5, 8, 14, 1, 5678 };
  int tempVar;
  for (int i = 0; i &lt; numbers.length; i++)
  {
     for(int j = 0; j &lt; numbers.length; j++)
     {
              if(numbers[i] &gt; numbers[j + 1])
              {
                     tempVar = numbers [j + 1];
                     numbers [j + 1]= numbers [i];
                     numbers [i] = tempVar;
              }
     }
  }
  for (int i = 0; i &lt; numbers.length; i++)
  {
       System.out.println(numbers[i].toString());
  }
  </code></pre>
  
  <p>Is this tutorial correct at all?
  <a href="https://blog.udemy.com/bubble-sort-java/" rel="nofollow">https://blog.udemy.com/bubble-sort-java/</a></p>
  
  <p>I followed the example and applied it to Last Names in an arraylist, but the results are a bit wack.</p>
  
  <pre><code>String a;
  String b;
  Person c;
  Person d;
  
  for (int i=0; i&lt; list.size(); i++){
  
      for(int j=0; j&lt; list.size()-1; j++){
  
           a = list.get(i).getLastName();
           b = list.get(j+1).getLastName();
           c = list.get(i);
           d = list.get(j+1);
  
           if ( a.compareTo(b) &lt; 0 )  {
  
               Person temp = d;
               list.set(j+1, c);        
               list.set(i, temp); 
           }
       }
   }
  </code></pre>
  
  <p>I'd really like to get a grip on a few methods (like figuring out why my comparator didn't work), but right now I'd just like to get a Bubble Sort to work correctly. Thanks.</p>