1.

How To Compare Two Strings In Java?

Answer»

equals() METHOD can be used for COMPARING two strings in Java. If you want to ignore case then you can use equalsIgnoreCase(STRING anotherString) method. 

There are also compareTo() and compareToIgnoreCase() methods for comparing two strings lexicographically. Returns an INTEGER indicating WHETHER this string is greater than (result is > 0), equal to (result is = 0), or less than (result is < 0) the argument. 

You can also use matches() method where you can pass a regular expression for matching strings.

equals() method can be used for comparing two strings in Java. If you want to ignore case then you can use equalsIgnoreCase(String anotherString) method. 

There are also compareTo() and compareToIgnoreCase() methods for comparing two strings lexicographically. Returns an integer indicating whether this string is greater than (result is > 0), equal to (result is = 0), or less than (result is < 0) the argument. 

You can also use matches() method where you can pass a regular expression for matching strings.



Discussion

No Comment Found