for (int i = 0; i <= str.length(); i++)


str.length is = the index number of the last element + 1