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
What is another word for methodology?
What is a class in java?
What is a literal coding?
What are the methods of object class ?
What is role of void keyword in declaring functions?
What are static methods?
Differece between class and generic class?
Can extern variables be initialized?
What is entry set in java?
What does the “final” keyword mean in front of a variable? A method? A class?
What is sizeof in java?
What are peerless components?
Explain the differences between static and dynamic variables?
What is the difference between interface & abstract class?
How can you make sure that your singleton class will always return single instance in multi-threaded environment?