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. Thanks.
View Tutorial          By: Joe at 2011-12-07 11:41:14

2. it doesn't count for the values like 001 or 02 et
View Tutorial          By: angesh at 2012-02-10 16:15:02

3. This explanation is simple and very useful.
View Tutorial          By: kiran at 2015-02-22 20:47:13

4. i should say, a lot of thank you because of this s
View Tutorial          By: merven at 2009-03-17 09:45:39

5. How can I use stack in entering a letter and will
View Tutorial          By: mards at 2014-10-17 12:18:34

6. Hi..All ...to run this programs.first of of all u
View Tutorial          By: raavi.surendra at 2011-12-29 05:34:06

7. Very good explanation . I was very confuse but rea
View Tutorial          By: Shahabaj at 2010-08-10 08:58:39

8. You don't have to call the constructors. When you
View Tutorial          By: Watson at 2011-05-04 10:44:23

9. Can anybody send full code for sending and receivi
View Tutorial          By: Jayapal at 2010-08-12 11:41:38

10. can anyone tell how to send sms in asp.net using p
View Tutorial          By: dubail at 2013-04-06 14:17:44