title: Arraylist and InsertionSort Object
body: <p><strong>Question</strong></p>
  
  <p>I need to use Insertionsort to sort my ArrayList of <code>&lt;klant&gt;</code> on an element (Achternaam).
  How do i do that?</p>
  
  <p><strong>Code</strong></p>
  
  <p>The code im using for insertion sort gives me a few errors because i am using a Arraylist instead of the 1000's of examples with array's.</p>
  
  <pre><code>public class InsertionSort {
  
  public static void insertionSort(ArrayList&lt;Klant&gt; klanten){
      for(int i = 1; i &lt;klanten.size(); i++){
          Comparable objectToSort = klanten.get(i);
          int j = i;
          while(j &gt; 0 &amp;&amp; klanten[j-1].compareTo(objectToSort) &gt; 1){
              klanten[j] = klanten[j-1];
              j--;
          }
          klanten[j] = objectToSort;
      }
  }
  }
  </code></pre>
  
  <p><em>The Klant.class has several getters and setters which return its variables one of them is <code>getAchternaam()</code> which returns the achternaam String.</em></p>
  
  <p>calling the code:</p>
  
  <pre><code>ArrayList&lt;Klant&gt; klanten = new ArrayList&lt;Klant&gt;();
  InsertionSort stringsort = new InsortionSort();
  stringsort.insertionSort(klanten);
  </code></pre>
  
  <p>What am i doing wrong and how can i fix it?</p>
  
  <p><em>Everywhere in the <code>code insertionSort.class</code> at <code>klanten</code> is a error</em></p>
  
  <blockquote>
    <p>'The type expression must be an array but it resolved to ArrayList
    &lt; klant></p>
  </blockquote>