[5077] in java-interest

home help back first fref pref prev next nref lref last post

Re: Strings.substring() and the == operator

daemon@ATHENA.MIT.EDU (Pat Niemeyer)
Sun Jan 28 07:38:07 1996

Date: Sun, 28 Jan 1996 05:23:01 -0600 (CST)
From: Pat Niemeyer <pat@icon-stl.net>
To: Walter Szewelanczyk <Walter@stumpy.adco.com>
cc: java-interest@java.sun.com
In-Reply-To: <199601280726.XAA08717@java0.javasoft.com>



On Sun, 28 Jan 1996, Walter Szewelanczyk wrote:

> I have a problem using the == operator on Strings.  If I asign a 

"==" is a test for identity not for equality.  
You should always use equals() instead.

Because strings are immutable, they can be shared and you will find that
Java sometimes gives you the same reference for identical strings. 
This happens, for example, when you embed two identical literal string 
references in the same class.  But when you take a substring, or some other
behavior the string may be copied.


Pat
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post