Comment on Tutorial - equals( ) Versus == in Java By Mashoud



Comment Added by : Miguel JImenez

Comment Added at : 2009-05-10 14:28:46

Comment on Tutorial : equals( ) Versus == in Java By Mashoud
Thanks for the explanation.
It makes sense. However, I tried this:

String s1 = "Hello";
String s2 = "Hello"; // new String(s1);
System.out.println(s1 + " equals " + s2 + " -> " + s1.equals(s2));
System.out.println(s1 + " == " + s2 + " -> " + (s1 == s2));

and I don't understand the result.
Can someone explain why both result in equal. please?

MJ


View Tutorial



Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. very good explanation for Include Action in struts
View Tutorial          By: VIshwanath at 2011-03-21 06:00:22

2. wonderful
simplified description
ke

View Tutorial          By: ephrem at 2010-01-14 06:12:05

3. Its nice and really apriciate rakesh sir i try t
View Tutorial          By: prince at 2013-04-18 09:46:34

4. Hi all, i have tried above code, but am getting fo
View Tutorial          By: swathi at 2010-06-24 05:18:28

5. grt tutorial
View Tutorial          By: sss at 2009-08-30 03:33:13

6. thanx it was really helpful
View Tutorial          By: Vidisha at 2010-07-09 06:21:32

7. Please note that the above code does not work with
View Tutorial          By: mk at 2012-02-15 10:59:49

8. werst program out put nt comming
View Tutorial          By: anu at 2012-08-02 13:09:00

9. how to connect jdbc in java on mysql
View Tutorial          By: saravana kumar at 2012-01-30 06:06:57

10. java.lang.IllegalArgumentException
at java

View Tutorial          By: gopal at 2011-03-21 00:45:51