what is the difference between equals method and ==

Answer Posted / chanchal verma

== compares the reference values whether they are pointing to the same object or not. equals() method compares the contents of two objects.
Ex.
String s1=new String("chanchal");
String s2=new String("chanchal");
System.out.println(s1==s2);// prints false
System.out.println(s1.equals(s2));

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is generic class?

652


What is the difference between static class and normal class?

494


What are the two types of java?

522


Why is string class considered immutable?

598


What is nan inf?

513






Where is the find and replace?

538


What is difference between module and function?

544


Explain about doubly linked list

623


Can list have duplicates in java?

523


Explain the importance of finalize() method.

569


How you can force the garbage collection?

542


What is the Difference between Final Class && Abstract Class?

619


What is the use of protected in java?

538


List some features of the abstract class.

597


What is the benefit of singleton pattern?

529