Actually i’m comparing two string which returns true when i use equals method. Whereas when i use compareTo method it returns 22.
Also i want to know at what place those two Strings differ. Using java how do i find this?
Thanks in advance.
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.
According to the documentation of compareTo()
Hence, 22 is not the position of the differing character in the two strings, but the distance between the first dissimilar characters.
As for your second question, I believe a simple iteration through the characters in both strings will allow you to pinpoint easily the first character position where they differ