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

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

Java program to check if user input is an even number

Archived Comments

1. what about the remaining explanation......do anyth
View Tutorial          By: raki at 2011-11-07 10:47:25

2. Hi Ramalak,
My modem is connected to COM3 p

View Tutorial          By: divya at 2008-04-30 23:19:26

3. hi i want to run a c program in java program but i
View Tutorial          By: jyothi at 2014-11-27 06:40:27

4. thanks!!
View Tutorial          By: eoko at 2011-05-10 23:34:29

5. hi Ashray P Shetty,
I'm getting the followi

View Tutorial          By: Balaji at 2010-11-25 14:16:23

6. Works like a charm for me ! but i stuck with an is
View Tutorial          By: santosh at 2014-12-17 12:44:09

7. It must be the last thread to finish execution. Wh
View Tutorial          By: Abinash at 2013-07-16 06:37:11

8. It is a good tutorial but I think the "Instru
View Tutorial          By: Jaypee at 2010-10-10 22:40:50

9. How can I delete the data that I have entered into
View Tutorial          By: selina at 2011-08-15 05:15:45

10. i m happy this programs thsk
View Tutorial          By: jai at 2011-05-09 14:20:35