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. nice tutorial
View Tutorial          By: Raman at 2014-11-13 07:47:11

2. i am not sure of this line(depends on your jvm) ,
View Tutorial          By: vpeddi at 2010-03-20 07:20:19

3. EJB's can be deployed on multiple servers and when
View Tutorial          By: Tomek at 2011-09-12 12:29:07

4. Hi
I tried to use this class , I don't get

View Tutorial          By: arnav at 2015-03-27 06:01:22

5. Thanks!
Please point me to a site which di

View Tutorial          By: TERRY DEGLOW at 2012-01-29 16:04:41

6. sir, i need java code to display position and velo
View Tutorial          By: Sandhya Yadav at 2015-08-20 07:16:04

7. sir , i am new in j2me and i want to learn more s
View Tutorial          By: vipin Luhach at 2012-01-19 06:43:27

8. Excellent. I got stuck in a huge project and was f
View Tutorial          By: Rahul Tiwari at 2010-12-08 22:40:29

9. Just what I needed. Thank you.
View Tutorial          By: Clive Jefferies at 2009-06-01 08:05:15

10. To DD -

The comment you just posted

View Tutorial          By: Alex at 2011-09-30 10:36:11