title: Java sort ArrayList using bubblesort
body: <p>I have been working on this for the past 5 hours. For some reason I am not getting the result I am looking for. The method is supposed to sort an <code>ArrayList</code> of items by quantity using bubble sort. Not sure if I am making a mistake but it seems to only sort the first few items and just lists the rest as they are and not in order.
  Here is the code:</p>
  <pre class="lang-java prettyprint-override"><code>public static void bubblesrt(ArrayList&lt;Drinks&gt; list)
  {
      Drink temp;
      if (list.size()&gt;1) // check if the number of orders is larger than 1
      {
          for (int x=0; x&lt;list.size(); x++) // bubble sort outer loop
          {
              for (int i=0; i &lt; list.size()-i; i++) {
                  if (list.get(i).compareTo(list.get(i+1)) &gt; 0)
                  {
                      temp = list.get(i);
                      list.set(i,list.get(i+1) );
                      list.set(i+1, temp);
                  }
              }
          }
      }
  
  }
  </code></pre>
  <p>and this is the <code>compareTo()</code> method which is located in a <code>Drinks class</code></p>
  <pre class="lang-java prettyprint-override"><code>public int compareTo(Drinks z) 
  {
      int res=0;
      if (quantity &lt; z.quantity) {res = -1;}
      if (quantity &gt; z.quantity) {res = 1;}
      return res;
  }
  </code></pre>
  <p>How do I make this work as intended?</p>