Wednesday 18 November 2015

How do you check if two Strings are equal in Java

There are two ways to check if two Strings are equal or not - using "==" operator or using equals method. When we use "==" operator, it checks for value of String as well as reference but in our programming, most of the time we are checking equality of String for value only. So we should use equals method to check if two Strings are equal or not. There is another function equalsIgnoreCase that we can use to ignore case.

Example:

No comments:

Post a Comment