Comment on Tutorial - equals( ) Versus == in Java By Mashoud



Comment Added by : saurabh

Comment Added at : 2009-07-30 15:19:49

Comment on Tutorial : equals( ) Versus == in Java By Mashoud
There is no need to fight. ...whatever ku is saying is correct and what arpita experienced is also correct.
Ku will be correct if I say
String s1 = "Hello";
String s2 = "Hello";
the big difference is here I am not explicitly creating a new object , instead if I had used String s2 = new String ("Hello") just like in thread 1 then I will get s1 == s2 not true which arpita got. Arpita if you try s2 = "Hello" in your program you may get true (depends on your jvm)

One more thing what ku said is JVM specific, a particular JVM can choose to maintain String pool while other may not.
String API just guarantees that equals() will work as intended but not == .


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. thank you.
View Tutorial          By: lluulnw at 2014-11-22 12:39:35

2. errr! how about reopening the file, and transfer t
View Tutorial          By: szel at 2010-10-05 20:01:04

3. Able to connect to mobile
Unable to send me

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

4. Hi this is very clear and helpful, I would like to
View Tutorial          By: JoelC at 2012-11-06 16:23:19

5. sooooooooooooooooo gr8 jop!!
View Tutorial          By: monti at 2011-06-14 08:40:55

6. I didnt get the use of public Sting toString().. I
View Tutorial          By: Pradesh at 2010-05-06 05:38:23

7. Thanks a lot!
The main reason why we need t

View Tutorial          By: SA at 2011-06-24 15:00:13

8. no output is shown
View Tutorial          By: shubham bansal at 2015-02-21 15:36:31

9. Its of the type "Direction"...Enum type
View Tutorial          By: Avinash at 2010-10-29 04:53:35

10. Very nice article.... explained the concept very n
View Tutorial          By: prashant yeole at 2010-12-16 03:15:07