 <p>As I mentioned in my comment, you only need one loop to solve this problem:</p> <pre><code>public static boolean isStringArraySorted(String[] strs, int n) { for (int i = 0; i &lt; strs.length - 1; i++) { String first = substring(strs[i], n); String second = substring(strs[i + 1], n); if (first.compareToIgnoreCase(second) &gt; 0) { return false; } } return true; } private static String substring(String s, int n) { return s.substring(0, n &gt; s.length() ? s.length() - 1 : n); } </code></pre>