Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!

# equals n ==

usha prithvi
Ranch Hand
Posts: 31
hi,

Please explain the difference between == n equal? n how it works in Strings?

Thankz

Barry Gaunt
Ranch Hand
Posts: 7729
What's the value of n?

usha prithvi
Ranch Hand
Posts: 31
I am sorry.Itz and. What is the difference between == and equals? how does it work in Strings? Thankz

Barry Gaunt
Ranch Hand
Posts: 7729
This is a very basic question so I'd better move it to our Java In General (Beginner) forum.

Hentay Duke
Ranch Hand
Posts: 198

This is the simple answer. Someone else may give you a more in-depth answer.

Steve Morrow
Ranch Hand
Posts: 657
Here's an excellent article that you should read:
Comparison operators: equals() versus ==

Please make the extra effort to write out words such as "and". The extra keystrokes won't cost much in the way of time, and the enhanced clarity will be appreciated by those communicating on a forum with international readership.

Srinivasa Raghavan
Ranch Hand
Posts: 1228
equals() is used to check whether two objects are meaningfully equal & == is used to check whether if two instances are equal.

From K&B book :-

[ When you really need to know if two references are identical, use ==. But when you need to know if the objects themselves (not the references) are equal, use the equals() method. ]

For String & Wrapper classes this equals() method is Overrided, For your own class you need to override the equals if you want to check whether two objects are meaningfully equal.

Layne Lund
Ranch Hand
Posts: 3061
Originally posted by usha prithvi:
I am sorry.Itz and. What is the difference between == and equals? how does it work in Strings? Thankz

I think the point of the question about "what is n?" means that you need to use proper English. "Itz" isn't a word either. We try to maintain a somewhat professional appearance around here. This is especially important when you ask questions if you really want us to take you seriously. Please avoid l33t and other chat-like abreviations. It usually detracts from the point that you want to make and might even prohibit us from understanding you altogether.

Layne