Last active
December 21, 2019 04:03
-
-
Save gauravkukade/431cd4899af2b991d306931afd123a17 to your computer and use it in GitHub Desktop.
A Java program to compare two strings using equsls() and equalsIgnoreCase() method of the String. The code snippet is used in a blog at https://coderolls.com/comparing-strings-in-java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A Java program to compare two strings using equsls() | |
* and equalsIgnoreCase() method of the String. | |
* | |
* @author Gaurav Kukade at coderolls.com | |
*/ | |
public class CompareUsingEquals { | |
public static void main(String[] args) { | |
String firstString = "coderolls"; | |
String secondString = "javablog"; | |
String thirdString = "coderolls"; | |
String fourthString = "CodeRolls"; | |
System.out.println("Comparing strings using equals() and equalsIgnoreCase() method\n"); | |
// Using equals() method | |
System.out.print("firstString.equals(secondString) : "); | |
System.out.println(firstString.equals(secondString)); | |
System.out.print("firstString.equals(thirdString) : "); | |
System.out.println(firstString.equals(thirdString)); | |
/* | |
* Using equalsIgnoreCase() method to ignore | |
* case consideration (i.e. Capital or small) of both the strings. | |
*/ | |
System.out.print("firstString.equalsIgnoreCase(fourthString) : "); | |
System.out.println(firstString.equalsIgnoreCase(fourthString)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment