Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: == operator for String



Dmitry,

Use the equals() method, not == for strings. Strings are classes, not
primitive types.

String testString = "test";
testString += "1";
if(testString.equals("test1")){
System.out.println("== equal");
}else{
System.out.println("== not equal");
}

Branden Root
Web Developer
Portent Interactive
email@hidden


-----Original Message-----
From: email@hidden
[mailto:email@hidden]On Behalf Of Dmitry Markman
Sent: Thursday, August 29, 2002 3:39 PM
To: email@hidden
Subject: == operator for String


Hi,
as I understand how operator == works
following code will produce output
== not equal


String testString = "test";
testString += "1";
if(testString == "test1"){
System.out.println("== equal");
}else{
System.out.println("== not equal");
}

after compilation and running that code on MAC OS X I really received
"== not equal"
no surprise :-)

but here is a question, if you look at source of class
java.beans.XMLDecoder
from 1.4 JDK you will see many places like that:

if (name == "null" ||
name == "string" ||
name == "class" ||
isPrimitive(name)) {
return;
}

or

if (name == "void") {
how it could work?

so my question is there some changes to Java Language related to
operator == for strings?
(I tried to look for languages changes on sun site, but didn't found,
maybe I didn't try hard enough :-( )
thanks
Dmitry Markman
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/java-dev
Be sure to read the FAQ http://developer.apple.com/java/faq/ before posting
Do not post admin requests to the list. They will be ignored.
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Be sure to read the FAQ http://developer.apple.com/java/faq/ before posting
Do not post admin requests to the list. They will be ignored.

References: 
 >== operator for String (From: Dmitry Markman <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.