Skip to content

Instantly share code, notes, and snippets.

@bzdgn
Created March 7, 2016 08:07
Show Gist options
  • Save bzdgn/612d8faa19a91cf047dc to your computer and use it in GitHub Desktop.
Save bzdgn/612d8faa19a91cf047dc to your computer and use it in GitHub Desktop.
Equals and == Operator Demonstration
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]);
}
}
@bzdgn
Copy link
Author

bzdgn commented Mar 7, 2016

Output;

== Operator says : Hello != Hello
.equals() says : Hello = Hello

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment