title: How do I fix this IndexOutOfBoundsException even though my program is giving me the result i want?
body: <p>I made a small little program that picks a given word out randomly then shuffles it. The program is giving me the right results, but i get an IndexOutOfBoundsException. How do I fix it. I think the problem is downward from line 16 and on.</p>
  
  <pre><code>import java.util.Collections;
  import java.util.LinkedList;
  import java.util.Random;
  
  public class Scramble {
     public static void main (String[] args) {
        String[] words= {"hat", "bubble", "camcorder"};
        Random rand = new Random();
        int endNum = rand.nextInt(3);
        for (int i=0;i&lt;=endNum;i++) {
           int alt = endNum;
           if (alt==0 || alt ==1 || alt==2) {
              String ChosenWord=words[alt];
              LinkedList&lt;Character&gt; lnk = new LinkedList&lt;Character&gt;();
              for (int j=0;j&lt;=ChosenWord.length()-1;j++) {
                 lnk.add(ChosenWord.charAt(j));
              }
              Collections.shuffle(lnk);
              for (int p=0;p&lt;=lnk.size();p++) {
                 char addLet=lnk.get(p);
                 String wholeWord=""+addLet;
                 System.out.print(wholeWord);
               }
            }
         }
      }
  }
  </code></pre>