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



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. the above code works fine for. May someone help wi
View Tutorial          By: T.T at 2012-02-23 06:22:36

2. very simple example.....................
View Tutorial          By: kajal at 2015-08-22 09:28:16

3. how to write an byte array containing 10 different
View Tutorial          By: sanjana at 2015-01-17 06:32:41

4. thanks for he info, was looking everywhere for som
View Tutorial          By: John at 2011-05-16 11:28:54

5. Imports Excel = Microsoft.Office.Interop.Excel

View Tutorial          By: Nilesh at 2014-12-01 13:45:25

6. i have written above code but the values are not s
View Tutorial          By: varun at 2010-01-15 18:37:19

7. I running this on localhost offline and getting er
View Tutorial          By: nitisha at 2011-05-14 09:18:16

8. Hi Friends,
Saw all of your comments. The a

View Tutorial          By: Avinash at 2011-11-28 04:43:09

9. Able to connect to mobile
Unable to send me

View Tutorial          By: Prashant at 2011-04-24 01:16:27

10. I am using my NOKIA 2700 via blutooth connection.
View Tutorial          By: Rahi at 2010-05-11 04:39:33