Java String compare to determine Equality
by, 04-26-2012 at 07:59 PM (429 Views)
Comparison of the java string could be done in various ways, as given below. It is dependent upon javastringcompare type that which of them will be used.
* == Operator
* equals method
* compareTo method
Comparing, by using the “== Operator”
When String object references are compared, ==operator is used. If 2 variables of String are pointed towards similar object present in memory, then comparison will be returned true. In other case it will return false. It shall be noted that ==operator is not for comparison of the text content which is present in String objects. Just the two string references are compared by it. Given program will be printing “strings are not equal”, in first case. Otherwise, “strings are equal” in 2nd one.