Skip Top Navigation Bar
Current Tutorial
Finding the Index of a String in Another String

Finding the Index of a String in Another String

Your Weekly Java Snippet 002

Snippet: Using compareTo() to Compare Strings with Different Cases

Explanation

This snippet explores how compareTo() behaves when the strings differ only in case. The result of the comparison may be not intuitive. Remember, lowercase letters comes after uppercase letters.

What You Can Do

Try using compareToIgnoreCase() on the same three strings. Do all comparisons now return 0?

Run it and observe the output!


Last update: May 1, 2026


Current Tutorial
Finding the Index of a String in Another String