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. To 15:
Sometimes it is useful to return the

View Tutorial          By: Anderson Goulart at 2010-08-24 19:15:14

2. I need one help how to update particular column da
View Tutorial          By: santhosh.s at 2015-01-22 15:09:33

3. This is just Great, didn't find anything like this
View Tutorial          By: Vikrant Verma at 2012-10-07 04:54:42

4. This is good for beginners.
View Tutorial          By: sathish at 2011-04-05 11:37:30

5. Having this error while using comm.jsr for sending
View Tutorial          By: Amit Kumar at 2013-10-15 09:04:58

6. if u need simple definition then that are

View Tutorial          By: rizvaankhan at 2011-10-10 13:13:36

7. Hi Doug,

This code is for Javascrip

View Tutorial          By: Ramlak at 2008-12-04 02:47:44

8. Excellent information reg the scopes of jsp , plea
View Tutorial          By: venkateshwarreddy suravaram at 2012-01-09 08:34:23

9. Is it possible for you to create for me a mobile a
View Tutorial          By: Meme at 2008-12-23 06:24:42

10. hi sr.
do u have any idea , how to convert

View Tutorial          By: gohila at 2012-08-15 14:31:31