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. the below error can be solve by another version co
View Tutorial          By: prasad raju v at 2010-04-08 04:20:10

2. good
View Tutorial          By: rajesh sharma at 2011-07-18 05:20:56

3. Simpler example:

import java.io.*;

View Tutorial          By: Joseph Harner at 2011-12-04 23:20:48

4. but how is the string concatenation done with the
View Tutorial          By: Vipin at 2009-05-09 03:08:51

5. Thnaks a lot. Deep in brief.
View Tutorial          By: Thanks at 2012-05-23 03:36:37

6. Its working perfectly for me.Thanks so much for pr
View Tutorial          By: Sunpenn at 2009-10-13 00:53:09

7. hello guys... plz help me in j2me i want to learn
View Tutorial          By: bishnu prakash at 2011-07-11 13:18:39

8. Hi, I cant open the file after I click Write SD. I
View Tutorial          By: hassan at 2014-12-17 07:44:16

9. Thank You very much :)
View Tutorial          By: RaghuCK at 2010-09-09 13:53:26

10. good
View Tutorial          By: saravanan at 2007-03-02 23:16:00