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. Hiiii

When I am executing

View Tutorial          By: Souvik Bhattacharya at 2008-08-18 00:21:31

2. Dude how did you used out.print() method it is giv
View Tutorial          By: Hardik at 2013-02-18 15:37:09

3. hi,
i use spinner concept in my project but

View Tutorial          By: lavanya at 2013-03-01 06:25:01

4. its not solve my problem.i.e
the concept is

View Tutorial          By: murli at 2010-10-02 23:23:11

5. I have a source code of j2ee. but i want to conver
View Tutorial          By: bangaram at 2011-06-07 09:28:45

6. very very useful..thank you
View Tutorial          By: sridaran at 2009-03-21 00:45:21

7. i have to learn java
View Tutorial          By: md arif alam at 2013-04-15 18:30:27

8. i am developing a video streaming pc server to j2m
View Tutorial          By: ziathegreat at 2009-05-19 13:19:15

9. very good to use
View Tutorial          By: baby at 2013-06-14 12:08:14

10. It's very useful to j2me beginners
View Tutorial          By: Naresh Padam at 2009-01-05 05:52:53