programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# equals n ==

Ranch Hand
Posts: 31
hi,

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

Thankz

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.

Ranch Hand
Posts: 198

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

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.

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.

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

 With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.