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. Declaring int result within the method will change
View Tutorial          By: Soph at 2013-02-06 06:11:39

2. SMSC number is the sms center no. put the sim to a
View Tutorial          By: Java MAn at 2012-01-28 19:08:23

3. The site is too informative. I just like their imm
View Tutorial          By: Priyadarshi Tripathi at 2010-10-26 23:44:46

4. can any body help me,i need to send a sms from sim
View Tutorial          By: vinayaka DJ at 2011-11-14 12:44:01

5. I need some help. I am a programmer - but quite n
View Tutorial          By: Ron at 2013-06-21 00:58:27

6. why push is error in st.push(new Integer(a)); ? an
View Tutorial          By: ann at 2015-02-02 09:23:41

7. your nice
View Tutorial          By: rymer at 2011-03-23 01:30:41

8. hi....
i want to send sms to any mobile by

View Tutorial          By: prerna at 2010-07-09 20:15:48

9. Good job. Very clear and concise and a great help.
View Tutorial          By: Eduardo at 2012-02-08 19:18:50

10. # include <iostream.h>
int main ()
View Tutorial          By: nazarine at 2011-07-06 06:17:10