



greater than 0: the caller string is greater than the argument string.The following integer values are returned: This method is necessary because its not possible to compare strings using the equality operator (). The compareTo() method is used to know whether or not strings are identical. Compares two strings to see if they are the same. Like the equality operator, the inequality operator will attempt to. It is the negation of the equality operator so the following two lines will always give the same result: x y (x y) For details of the comparison algorithm, see the page for the equality operator. The equals() method is used to compare the characters inside a string object whereas, the = operator is used to compare two object references to see whether they refer to the same instance. The inequality operator checks whether its operands are not equal. We often get confused while using equals() and =, but they are used to perform two different operations. This can also be referred to as a specialized form of regionMatches(). The startsWith() method helps us check whether a given string begins with a specific substring, whereas endsWith() is used to check whether a given string ends with the specific substring given. "Hello World".regionMatches(true, 6, "world", 0, 4) //true "Hello World".regionMatches(6, "world", 0, 4) //false Java also offers an overloaded form that helps us to compare strings while ignoring their case differences. The regionMatches() method is used to compare a specific region in one string with a specific region in another string.
