what is the difference between equals method and ==

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain wait() method of object class ?

630


Is arraylist an object in java?

598


What is the do while loop syntax?

551


Can we use catch statement for checked exceptions when there is no chance of raising exception in our code?

588


What is string data?

551






What do you mean by JVM?

585


What do you mean by access modifier?

552


What is the difference between compile-time polymorphism and runtime polymorphism?

558


How do you achieve singleton?

529


What is the covariant return type?

576


What is the difference between assignment and initialization?

554


What happens to the Exception object after handling an exception?

1811


What value is a variable of the string type automatically initialized?

609


What is final keyword in java?

547


do I need to use synchronized on setvalue(int)? : Java thread

551