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. I am running it within NetBeans. I set a breakpoin
View Tutorial          By: PeteC at 2014-02-22 18:57:14

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. Daniel, i think you need another func, also you ca
View Tutorial          By: רופא שיניים at 2009-08-15 16:48:07

4. good tutorial
View Tutorial          By: mohang at 2011-12-24 05:24:56

5. Nice Example. Gives very clear idea.
View Tutorial          By: Larsen at 2013-09-14 02:29:24

6. thanks
View Tutorial          By: nitin at 2010-03-29 01:02:57

7. It would be nice to add the line,


View Tutorial          By: Anonymous at 2009-08-30 07:59:10

8. where is the main class .
View Tutorial          By: rishi at 2015-10-02 10:17:17

9. The iterator returned by iterator() does not point
View Tutorial          By: Jeffrey at 2009-10-06 21:45:41

10. hello sir i want to know how to run this pogram as
View Tutorial          By: Pranjay at 2009-01-07 03:33:45