If i were to compare the String “1” to the string “7” which one would be bigger. Also if I compare the string “1” to the string “Test” which one would be bigger?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A comparison of Strings in Java is done character by character. Each character has a specific ranking to it based on where it appears in the Unicode character table (for this case, we can use ASCII, since it’s English).
“1” would be considered less than “7”, as well as “T”.
To invoke (place this inside of
main():You’ll get negative valued results – these are the distances in terms of ASCII point from the character you’re comparing to.
compareToIgnoreCase()compares the values within the lowercase ASCII range, so this is why the value of the lastcompareToIgnoreCase()is so low.