String Comparisons
The String class provides the methods for comparing strings, as given below:-
Method Defination
str2.equals(s1: String): boolean Returns true if this string is equal to string s1.
str2.equalsIgnoreCase(s1: String): boolean Returns true if this string is equal to string s1 case insensitive.
str2.compareTo(s1: String): int Returns an integer greater than 0, equal to 0, or less than 0 to indicate whether this string is greater than, equal to, or less than s1.
str2.compareToIgnoreCase(s1: String): int Same as compareTo except that the comparison is case insensitive.
str2.regionMatches(index: int, s1: String, Returns true if the specified subregion of this string s1Index: int, len: int): boolean exactly matches the specified subregion in string s1.
str2.regionMatches(ignoreCase: boolean, Same as the preceding method except that you can index: int, s1: String, s1Index: int, specify whether the match is case sensitive.
len: int): boolean
str2.startsWith(prefix: String): boolean Returns true if this string starts with the specified prefix.
str2.endsWith(suffix: String): boolean Returns true if this string ends with the specified suffix.
The String class contains the methods for comparing strings.
Click on any method for program.
Method Defination
str2.equals(s1: String): boolean Returns true if this string is equal to string s1.
str2.equalsIgnoreCase(s1: String): boolean Returns true if this string is equal to string s1 case insensitive.
str2.compareTo(s1: String): int Returns an integer greater than 0, equal to 0, or less than 0 to indicate whether this string is greater than, equal to, or less than s1.
str2.compareToIgnoreCase(s1: String): int Same as compareTo except that the comparison is case insensitive.
str2.regionMatches(index: int, s1: String, Returns true if the specified subregion of this string s1Index: int, len: int): boolean exactly matches the specified subregion in string s1.
str2.regionMatches(ignoreCase: boolean, Same as the preceding method except that you can index: int, s1: String, s1Index: int, specify whether the match is case sensitive.
len: int): boolean
str2.startsWith(prefix: String): boolean Returns true if this string starts with the specified prefix.
str2.endsWith(suffix: String): boolean Returns true if this string ends with the specified suffix.
The String class contains the methods for comparing strings.
Click on any method for program.