Skip Top Navigation Bar

Using compareTo() to Compare Strings with Different Cases - Example 2

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!

Example List

Additional Resources