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. hai...
i am completed MCA am good at java.

View Tutorial          By: HEMALATHA at 2013-08-03 10:04:57

2. why we use the java in networking and What are the
View Tutorial          By: ali mohammed at 2015-10-11 22:34:36

3. java.lang.IllegalArgumentException
at java

View Tutorial          By: gopal at 2011-03-21 00:45:51

4. Thanks, much appreciated!
Saved a great dea

View Tutorial          By: alan at 2009-08-14 01:35:01

5. I am assuming you are using eclipse for your andro
View Tutorial          By: Ashley at 2011-07-18 00:34:04

6. Thank you very much for explaning the things in su
View Tutorial          By: Sunil Yadav at 2010-05-27 04:04:31

7. Is System.gc() required with finalize method??
View Tutorial          By: QsRealm at 2012-02-11 08:28:16

8. Excellent information in simple language. Its wort
View Tutorial          By: Rishi at 2011-11-04 05:03:24

9. s1==s2 is not true. its false. run the program and
View Tutorial          By: arpita at 2009-05-18 23:50:11

10. This program little hard to understand ..please gi
View Tutorial          By: sarav at 2011-02-17 05:02:46