title: Finding the string that is first in alphabetical order in an ArrayList of Strings
body: <p>I have an ArrayList of notes in the form of strings (an example of one would be "take out the trash". I have a notes class and one of the methods is supposed to go through the notes stored in the ArrayList and find the one that comes first in the alphabet. This is my current method:</p>
  
  <pre><code>public String firstAlphabetically() {
          String min = "";
          for (int i = 0; i &lt; notes.size(); i++) {
              for (int j = i + 1; j &lt; notes.size() + 1; i++) {
                  if ((notes.get(i)).compareTo(notes.get(j)) &lt; 0) {
                      min = notes.get(i);
                  } else {
                      min = notes.get(j);
                  }
              }
          }
          return min;
      }
  </code></pre>
  
  <p>However, when I run the program, I get an out of bounds error on this line: <code>for (int j = i + 1; j &lt; notes.size() + 1; i++)</code>. I know what an out of bounds error is but I can't figure out what part of that line would cause the program to crash. Could anybody tell me what I am doing wrong?</p>