Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 22nd, 2006, 6:10 PM   #11
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 4 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
I didn't know I could have used the "==" equality operator, I thought I had to use a pre-defined method in the Character class. You have to use ".equals()" for Strings and Strings are nothing but character arrays acording to the Java books I've been reading/read.
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Old Apr 22nd, 2006, 6:24 PM   #12
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 770
Rep Power: 3 Jimbo is on a distinguished road
Strings are objects (they even extend Object). While the underlying data structure is most likely a character array, Strings (obviously) have properties and methods. The purpose of a String is to hold a sequence of characters in a data type and perform whatever operations on that sequence. Because Strings are objects, using == compares the memory address of the object, rather than the value it holds. Because this hold for any object, the Object class defines a .equals() method for comparing the values of two objects. Primitive (non-object) types are simply data, without methods (global operators excluded). With primitives, using == compares the data in memory, not the address where the data is stored. Variables of type char are primitive. Hence, when you use:
String s = "some string";
if(s.charAt(5) == 's')
   System.out.println("It\'s an \'s\'.");
the == works because charAt returns a character, and comparing it to 's' (a char constant) will compare the values.

[edit:]
Quote:
Strings are nothing but character arrays
If you've ever used C++, this would be like comparing std::string to char*...
Jimbo is offline   Reply With Quote
Old Apr 22nd, 2006, 6:32 PM   #13
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 4 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
The beauty of Object Orientated Programming. So simple yet so complex!
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:35 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC