File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Comparision Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Comparision" Watch "Comparision" New topic


Ramgopal Reddy

Joined: Jan 28, 2006
Posts: 22
what is the difference b/w == and .equals

at what sistuations we use these two.

Someware i hears one is deepcomparison and other one is shallow comparison!

what r that words.

Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
The former is called the reference equality operator when both operands are a reference type (perhaps implicitly through autoboxing) - it compares the value of a reference to some other reference.

The latter is a method that is regularly used throughout the J2SE API Specification to determine "value equality" between two object instances. For example, in the Java collections API.

It might help to learn the difference between an object and an object reference:

Tony Morris
Java Q&A (FAQ, Trivia)
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
This is so not an advanced question! It's also an FAQ, isn't it?

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Originally posted by Peter Chase:
This is so not an advanced question!

Indeed. Let's move this to Java in General (Beginner.)

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Comparision
It's not a secret anymore!