In our previous Post # 96 Using equals( ) method for comparing two strings we've learnt that equals( ) method compares two string and gives true if and only if the both the words are same and are in same case.
i.e. "dog".equals("DOG"); -> Will give the output as false (Though the two words are same but dog is in lower case where as DOG is in upper case
But if you want to get the result as true when the two words are same but are of different case we've to use the equalsIgnoreCase( ) method as shown below:
"dog".equalsIgnoreCase("DOG"); -> Will give the output as true even though dog is in lower case and DOG is in upper case.
Lets implement this on Eclipse IDE:
1. Create 'equalsIgnoreCaseDemo' class under any project as shown below:
3. Observe that the output is displayed in the console as shown below:
Download this project:
Click here to download the project containing the class file used in this post (You can download this project and import into Eclipse IDE on your machine)
Please comment below to feedback or ask questions.
Using startsWith( ) and endsWith( ) methods will be explained in the next post.
No comments:
Post a Comment