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
- Learn: Declaring Strings
- Learn: Constructing a String
- Learn: Introduction to String Indexing
- Learn: Comparing Two String Objects Using compareTo Methods
- Learn: Comparing String Objects with equals Methods
- Learn: Obtaining Substrings from a String Object
- Learn: Using the split method on a String
- Practice: Evaluating Expressions that use the String Class
- Practice: Writing Code Using the String Class
- FRQ Practice: AP Computer Science A FRQ 1 Formatting Words
- FRQ Practice: AP Computer Science A FRQ 1 Sentence Analysis