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. HI, Thanks for your beautiful tutorial.

View Tutorial          By: Chintan at 2011-10-06 07:35:01

2. Plz send code of sending sms from java code...

View Tutorial          By: Shekh at 2014-11-27 14:18:25

3. hi can u send me the complete working code for sen
View Tutorial          By: Brajesh at 2011-04-21 03:07:40

4. hmmmmmm good
View Tutorial          By: Haritha chinnu at 2012-06-30 09:37:49

5. thank for your article it helps us to our studies
View Tutorial          By: shane at 2010-07-21 19:12:22

6. oh tnx a lot!i'v been lookin for a code like this!
View Tutorial          By: LES at 2012-01-13 12:55:09

7. Ur article is very intersting and very usefull me
View Tutorial          By: SIVAKUMAR at 2011-11-22 11:14:05

8. The example program was very easy to understand un
View Tutorial          By: vijay at 2011-12-27 07:34:35

9. hi could u tell me how to download a file using se
View Tutorial          By: akki at 2013-02-19 05:52:03

10. a bit extra information on robust
View Tutorial          By: mahesh at 2010-02-02 12:05:37