java tutorial - Compare two strings in Java - java programming - learn java - java basics - java for beginners
Learn java - java tutorial - compare two string in java - java examples - java programs
Comparing two strings:
- unicode value of each path character in the String.
- Returns negative int if first string is less than another
- Returns positive int if first string is grater than another
- Returns 0 if both strings are same.
int compareTo( String anotherString )
int compareTo( Object obj )
– It behaves accurately likecompareTo ( String anotherString)
- if argument object is of type String, or else throwsClassCastException.
int compareToIgnoreCase( String anotherString )
– It compares two strings ignoring the character case of the given String.