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. where i can find Messageressourse.properties......
View Tutorial          By: sanjiv at 2013-09-07 06:59:19

2. this is good, but i need a simple program about sh
View Tutorial          By: ramalakshmi at 2011-01-05 03:38:26

3. Thanks very much.
View Tutorial          By: Haritha at 2011-05-26 07:56:06

4. Till now, I have'nt done any certifications. I am
View Tutorial          By: Subhash at 2012-03-15 10:48:29

5. nice
View Tutorial          By: utkarsh at 2015-03-10 03:18:26

6. Definitely Struts is great. I have posted an artic
View Tutorial          By: Ashish at 2008-09-02 08:04:49

7. Hi puru, The syntax is substring(int startIndex, i
View Tutorial          By: Fazal at 2008-09-12 20:17:53

8. dear sir ,
How can i create my smtp or host

View Tutorial          By: jignesh at 2011-03-14 01:42:11

9. Yesterday afternoon, I tried a lot of different su
View Tutorial          By: Leo at 2011-07-26 04:19:15

10. Thanks so much, this was extremely helpful and rea
View Tutorial          By: gabrielle at 2013-10-04 22:07:17