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. Hello,
I've tried the above code, but I've

View Tutorial          By: Phyo Phyo at 2009-09-14 05:32:28

2. Hello Friends ,

s1 == s2 will alway

View Tutorial          By: Gunjan at 2010-09-08 19:24:24

3. I tried to use the code's but getting one error as
View Tutorial          By: Ashish at 2009-03-23 03:10:22

4. thanks ..it was really helpful.
View Tutorial          By: jay at 2012-03-19 04:17:14

5. Hi, i am newly in java,please send me on sample pr
View Tutorial          By: aruna.k at 2012-12-13 06:05:44

6. not that much clear exampl.. you should explain it
View Tutorial          By: elangovan at 2010-06-09 02:36:19

7. yes simple good it wroking goog
View Tutorial          By: durga prasad pavirala at 2009-02-11 03:43:04

8. good
View Tutorial          By: pardhuman at 2011-06-24 08:18:15

9. i get this msg when one of the clients close there
View Tutorial          By: Zero Code at 2009-07-16 14:05:14

10. It's simply nice.
View Tutorial          By: ghani at 2011-07-01 07:18:35