Java string compare by operator, equals, equalsIgnorecase


1. Java string compare by equalsIgnorecase:

       In this type of java string compare, we use trim() to trim the leading spaces of the string which was passed from main (leading spaces such as “  helloworld  ” the spaces before and after the string). The equalsIgnoreCase() will compare and ignore case sensitive between two strings. Two strings in this case are “HellWorld” and “helloworld”.
java-string-compare-two-chars-characters-by-equalsignorecase-1
The output:
True

1   1. Java string compare by operator “==”:

         Java string compare by operator is easy to apply. In this case, I use the second way to display the if statement to make it shrinker.  In the condition of if statement, I use “==” to make a comparison between two strings.  The output is true also.

java-string-compare-two-chars-characters-by-equalsignorecase-2



    3.     Java string compare by equals method:

         In this case, it slightly  different with java string compare by equalsIgnorecase above. I just use equals() method, which will include case sensitive. If our two strings are “hellolworld” and “HelloWorld”, the output will be false. In this case the output is true because two strings are similar.
java-string-compare-two-chars-characters-by-equalsignorecase-3
     To find out about about Point class in java:


   


     





Comments