Click to See Complete Forum and Search --> : String comparison
ngleeyean
December 7th, 2000, 11:23 PM
How to compare a string variable with a static string.
eg :
String compare,result
if (compare == "Video")
{ result = "Video is selected!"}; }
it seems like i cannot do the string comparison in this way.. how should i write it?
weaver
December 8th, 2000, 11:21 AM
if ( compare.equals( "Video" ) )
{
result = "Video is selected!";
}
-------------------------------------------
weaver
icq# 97002680
Please rate this post.
http://www14.brinkster.com/tsryan
Norm
December 8th, 2000, 07:04 PM
The == operator compares the two object references to see if they have the "same value". The value of an object reference is the address in memory where the object being referenced is stored. So if two object references point to the same object, then they will be ==. To compare the "contents" of an object requires that you use one of the object's methods. For String that method is equals(). Other classes/objects can have different methods to compare/test their contents.
Norm
raj_105_2000
December 9th, 2000, 01:45 AM
Use:
String compare, result;
if (compare.equals("Video")) result = "Video is selected.";
Rajendran
codeguru.com
Copyright WebMediaBrands Inc., All Rights Reserved.