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”.
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.
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.
Comments
Post a Comment