title: How to loop over arraylist and sorting based on starting character
body: <p>This was my assignment:</p>
  <p><em>Write and test a method that takes a List words, which contains Strings of alphabetic characters, throws them into 26 &quot;buckets&quot;, according to the first letter, and returns the ArrayList of buckets. Each bucket should be represented by an ArrayList. The first bucket should contain all the Strings from words that start with an 'a', in the same order as they appear in words; the second bucket should contain all the Strings that start with a 'b'; and so on. Your method should traverse the list words only once and leave it unchanged.</em></p>
  <p>So far my code looks like this:</p>
  <pre><code>public static ArrayList&lt;ArrayList&lt;String&gt;&gt; bucketSort(ArrayList&lt;String&gt; arr) {
          // Generate 26 bucket list
          ArrayList&lt;ArrayList&lt;String&gt;&gt; bucket = new ArrayList&lt;ArrayList&lt;String&gt;&gt;(26);
          for (int i = 0; i &lt; 26; i++) {
              bucket.add(new ArrayList&lt;String&gt;());
          }
          // Sort by char
          for (String v : arr) {
              for (int c=97; c &lt;=122; c++) {
                  if (v.startsWith(String.valueOf((char) c))) {
                      bucket.get(97-c).add(v.toUpperCase());
                  }
              }
          }
          return bucket;
      }
  </code></pre>
  <p>The only problem is that i'm getting indexoutofbounds error and I'm not sure why. The <code>97</code> and <code>122</code> refers to chars 'a' - 'z'. Think its correct because <code>(int) 'a'</code> gives me 97 and 122 for 'z'. I'm confused on why I'm getting index out of bounds.</p>