The
equals and equalsIgnoreCase are used to compare two Strings and states whether they are equal or not.
The
equals is represented as:
boolean equals(String str)
The equals will compare String str with the invoking String . It returns true if both the strings have same characters in same sequence else it returns false .The equalsIgnoreCase is represented as:
boolean equalsIgnoreCase(String str)
The equalsIgnoreCase() will compare String str with the invoking String Object. It returns true if both the strings have same characters in same sequence but it ignores the case differences i.e it considers [A-Z]=[a-z], A is same as a and Y is same as y .Here is the example program demonstrating these methods: StringComparisonequals and equalsIgnoreCase Demo CODE class EqualsDemo OUTPUT Hyderabad equals Hyderabad -- true DESCRIPTION The program consists of four output lines.
THINGS TO TRY
Dependent Topics :
|