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 equals method and ==

Answers were Sorted based on User's Feedback



what is the difference between equals method and ==..

Answer / subrahmanyam

== is userd to compare both are of same type
equals is used to compare both are of same contents


EX:
String s1="raju";
String s2=new String("raju");
if(s1.equals(s2))
System.out.println(" if(s1.equals(s2)"); //true
if(s1==s2)
System.out.println(" s1==s2"); //false

Is This Answer Correct ?    62 Yes 14 No

what is the difference between equals method and ==..

Answer / sandeep arora

== checks the reference value, that the reference are of
same object or not.

equals method check two strings are same or not

Is This Answer Correct ?    26 Yes 7 No

what is the difference between equals method and ==..

Answer / y.v.v.d.ravikanth

equals() method is from Object Class.So this is the method
to check the equality between two objects.This method
implements the equalence relation.

ex obj1 o1 = "ravi";
obj2 o2 = "ravi";

o1.equals(o2) ;// returns true.

== Operator. no doubt this is the operator. It can be used
in two ways
1:To compare the values of primitive variables.
2.To compare the object refference variables.
it returns true if refference variable reffering to the
same object.

ex obj1 a
obj2 b
obj1 c

a==c----> returns true.
a==b----> returns false.

Is This Answer Correct ?    17 Yes 7 No

what is the difference between equals method and ==..

Answer / ravikiran

equals will compare two objects,== will compare whether two
reference variables refer to same object or not

Is This Answer Correct ?    9 Yes 1 No

what is the difference between equals method and ==..

Answer / rajender

The Object class equals method refers address comparision.

Person p=new Person();
Person p1=new Person();

if(p.equals(p1){
//is always false.

}


the string class equals method refers content comparision

String p=new String ("java");
String p1=new String ("java");

if(p.equals(p1){
//is always true.

}


Dn't get confusion

Is This Answer Correct ?    5 Yes 1 No

what is the difference between equals method and ==..

Answer / sriragv

equal method also indirectly use == method i.e hashcode
(),there will be no difference b/w equals and == unless
until u override the equal method

Let me know if iam wrong

Is This Answer Correct ?    3 Yes 0 No

what is the difference between equals method and ==..

Answer / anoop

Normally == using to compare value type. If 2 object is
refering same memmory, it will return true otherwise false

Comparing object , you have to use equals, bz it will
compare all the values in it.

Is This Answer Correct ?    2 Yes 0 No

what is the difference between equals method and ==..

Answer / nagarjuna

equals method check the contents of the objects and returns
the boolean value.

== check the objects references

Is This Answer Correct ?    2 Yes 0 No

what is the difference between equals method and ==..

Answer / devarathnam c,kotagudibanda(po

Hi...
"equals()" method always compares the content of an
object,but "==" operator compares the memory locations
(references).
eg: String s1="KOTAGUDIBANDA";
Where "s1" is a reference and "KOTAGUDIBANDA"is a content.

Is This Answer Correct ?    6 Yes 6 No

what is the difference between equals method and ==..

Answer / suganthi

equals method will compare two strings where two strings are
equal or not but == method will compare reference variables.

Is This Answer Correct ?    4 Yes 4 No

Post New Answer

More Core Java Interview Questions

Can we convert stringbuilder to string in java?

0 Answers  


What is the difference between overriding & overloading?

0 Answers  


why do we use interface in java?

5 Answers  


Can we assign null to double in java?

0 Answers  


When a byte datatype is used?

5 Answers  


What restrictions are placed on method overloading and method overriding?

5 Answers  


How do you read and print a string in java?

0 Answers  


abstract class Demo { public void show() { System.out.println("Hello I am In show method of Abstract class"); } } class Sample extends Demo { public void show() { super.show(); System.out.println("Hello I am In Sample "); } } public class Test { public static void main(String[] args) { //I WANT TO CALL THE METHOD OF BASE CLASS IT IS POSSIBLE OR NOT CAN WE USE SCOPE RESOLUTION OPERATOR TO CALL OR JAVA NOT SUPPORTED THAT :: OPERATORE } }

3 Answers  


What will happen when using pass by reference in java?

0 Answers   HCL,


Write a program to find the whether a number is an Armstrong number or not?

0 Answers   Aspire, Infogain,


How to do a true java ping from windows?

0 Answers  


What is indexof?

0 Answers  


Categories