whats the difference between == and .equal ?
Answer Posted / haneef
see, every object created by the new operator, it has it own
hash code.
so when you compare with equals(), checks only content. But
with ==, it also checks the hashcode.
try this example
package app;
public class Test {
public static void main(String[] args) {
String str2 = new String("Haneef");
String str3 = new String("Haneef");
if (str2.equals(str3))
System.out.println("ok");
else
System.out.println("Not OK");
if(str2==str3)
System.out.println("ok");
else
System.out.println("Not ok");
}
}
u get
OK
NOT OK
| Is This Answer Correct ? | 7 Yes | 2 No |
Post New Answer View All Answers
In Java list the methods that can be overridden?
What are the differences between string and stringbuffer?
What is a flag variable?
What are assembly attributes?
What's the access scope of protected access specifier?
Can I override protected method in java?
Is call by reference possible in java?
explain the concept of virtual method invocation in polymorphism in detail?
What is an empirical question?
What does it mean that a method or field is “static”?
What is the latest version of java?
Is age a discrete variable?
Can we override a variable in java?
What is package protected in java?
What is the need of transient variables in Java ?