 <blockquote> <p><em>Is this logic better than recursion or conventional logic in terms of</em> time complexity?</p> </blockquote> <p>Assuming you are using the following recursive method,</p> <pre><code>public static boolean isPal(String s) { if(s.length() == 0 || s.length() == 1) return true; if(s.charAt(0) == s.charAt(s.length()-1)) return isPal(s.substring(1, s.length()-1)); return false; } </code></pre> <p>Time Complexity: <a href="http://www.cs.bilkent.edu.tr/~gunduz/teaching/cs201/slides/Recitation4.pdf" rel="nofollow">O(n)</a></p> <p><strong>equals:</strong></p> <pre><code>public boolean equals(Object paramObject) { if (this == paramObject) { return true; } if ((paramObject instanceof String)) { String str = (String)paramObject; int i = this.value.length; if (i == str.value.length) { char[] arrayOfChar1 = this.value; char[] arrayOfChar2 = str.value; for (int j = 0; i-- != 0; j++) { if (arrayOfChar1[j] != arrayOfChar2[j]) { return false; } } return true; } } return false; } </code></pre> <p>The complexity of your program is : O(n)+O(n)=O(n) </p> <hr> <blockquote> <p>How does compareTo() method checks if strings are equal? DOes it compare bytecode or something?</p> </blockquote> <p><strong>compareTo:</strong> returns 0 if the two strings are same or else it returns the difference, integer difference (i.e difference of Unicode values) of first non-matching characters,</p> <p>It does so by comparing characters at same positions of two strings</p> <pre><code> public int compareTo(String paramString) { int i = this.value.length; int j = paramString.value.length; int k = Math.min(i, j); char[] arrayOfChar1 = this.value; char[] arrayOfChar2 = paramString.value; for (int m = 0; m &lt; k; m++) { int n = arrayOfChar1[m]; int i1 = arrayOfChar2[m]; if (n != i1) { return n - i1; } } return i - j; } </code></pre>