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

Which method is used to force all the validation controls to run?

1076


What is the difference between client-side and server-side validations in webpages?

1067


What is the difference between dynamic SGA and static SGA?

1241


What are session state modes in asp.net?

1089


Is session stored in browser?

1013


How can I configure asp.net applications that are running on a remote machine?

1103


Can we have multiple master pages in asp net?

1031


What is difference between session and cookies?

1058


What are the advantages of asp.net?

1050


In which event are the controls fully loaded?

1051


How is mvc different from asp.net? : Asp.Net MVC

1100


What is a pixel url?

996


List all templates of the repeater control.

1151


What is state management in .net?

1130


What are the different properties of server control that exists?

1215