Created
March 7, 2016 08:07
-
-
Save bzdgn/612d8faa19a91cf047dc to your computer and use it in GitHub Desktop.
Equals and == Operator Demonstration
This file contains hidden or 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
public class EqualsOrOperatorDemo { | |
public static void main(String[] args) { | |
String str1 = "Hello"; | |
String[] strArray = new String[] { "animal", "donkey", new String("Hell") + new String("o"), "ox" }; | |
if( str1 == strArray[2] ) | |
System.out.println(" == Operator says : " + str1 + " = " + strArray[2]); | |
else | |
System.out.println(" == Operator says : " + str1 + " != " + strArray[2]); | |
if( str1.equals(strArray[2]) ) | |
System.out.println(" .equals() says : " + str1 + " = " + strArray[2]); | |
else | |
System.out.println(" .equals() says : " + str1 + " != " + strArray[2]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output;
== Operator says : Hello != Hello
.equals() says : Hello = Hello