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
Can singleton class be cloned?
Is {a, n, d} a palindrome? If you are given a random string, is it a palindrome or not?
What is complexity in java?
What string is utf8?
Explain the term virtual machine?
What are the library functions in java?
Does java allow overriding static methods ?
What are the two ways to create a thread?
How do I start learning java?
What is a boolean expression in java?
What is scope & storage allocation of static, local and register variables? Explain with an example.
What is static keyword in java?
Which method must be implemented by all threads?
How do you sort data in java?
Is ++ operator thread-safe in java?