Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What is the difference between a.Equals(b) and a == b?

Answer Posted / rajan

equals() method compares the state of an object i.e. it
compares the contents of the two objects.
but == compares the instance of the object i.e. it comparing
the identifier(references).
Ex:
public class Test2
{
public static void main(String args[])
{
// Create two equal but distinct strings
String a = new String(new char[]
{'h', 'e', 'l', 'l', 'o'});
String b = new String(new char[]
{'h', 'e', 'l', 'l', 'o'});

System.out.println(a==b);
System.out.println(a.equals(b));

// Now let's see what happens with the same tests

// with variables of type object
Object c = a;
Object d = b;

System.out.println(c==d);
System.out.println(c.equals(d));
}
}
Output is:
false
true
false
true
From the above example the String object is creating new
instances, so == compares the instances are equal are not.
equal() method compares the contents of a two object .

Is This Answer Correct ?    8 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What ports must be open for DCOM over a firewall? What is the purpose of Port 135?

2304


How you can add an event handler?

919


Which ASP.NET configuration options are supported in the ASP.NET implementation on the shared web hosting platform?

1071


Differentiate between namespace and assembly.

908


Can we store object in viewstate?

917


What is comparevalidator?

912


List the types of authentication supported by asp.net?

888


How many web.config files can I have in an application?

931


How can we communicate with each server in N-tier Architecture? and what are the methods?

2192


What is difference between asp.net and asp.net mvc? : Asp.Net MVC

966


What do you mean by authentication?

1018


How do u deploy ur project?

2630


What is the procedure to create the environment for asp.net? : asp.net mvc

979


What are directives in asp.net?

907


Why is the standalone environment only useful during the development process?

1768