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 the difference between Array and Hash Table?
How to create com object in Java?
What is a java string?
what is the use of bean managed and container managed with example?
What is parsing and its types?
What are different types of states exist for a thread?
Implement two stacks using a single array.
What is the difference between jvm and jre? What is an interface?
What are the different tags provided in jstl?
How do you implement tree mirroring in java?
What are inbuilt functions?
Why are generics used?
What is the purpose of the main method?
How can we create a synchronized collection from given collection?
What is a superclass?