title: Sorting ArrayList - IndexOutOfBoundsException -Java
body: <p>I'm trying to sort an ArrayList with strings(PlayersNames) and imageIcons(PlayersIcons) based on the values i store in an other arrayList with integers(results). 
  As you can see i get an indexOutOfBoundsException but i cant understand why. Maybe the earling of the morning makes me not to see plain things.</p>
  
  <pre><code>ArrayList&lt;String&gt; PlayersNames=new ArrayList&lt;String&gt;;
  ArrayList&lt;ImageIcon&gt; PlayersIcons=new ArrayList&lt;ImageIcons&gt;;
  
      public void sortPlayers(ArrayList&lt;Integer&gt; results){
          String tmp;
          ImageIcon tmp2;
          for (int i=0; i&lt;PlayersNames.size(); i++) {
              for (int j=PlayersNames.size(); j&gt;i; j--) {
  
                  if (results.get(i) &lt; results.get(i+1) ) {       //IndexOutOfBoundsException!
  
                      tmp=PlayersNames.get(i+1);
                      PlayersNames.set(i+1,PlayersNames.get(i));
                      PlayersNames.set(i,tmp);
  
                      tmp2=PlayersIcons.get(i+1);
                      PlayersIcons.set(i+1,PlayersIcons.get(i));
                      PlayersIcons.set(i,tmp2);
                  }
              }
          }
      }
  </code></pre>