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
Explain all java features with real time examples
What is method with example?
What are the different data types in java?
how to convert Java project into Maven ?
What is a literal coding?
What is a jagged array in java?
What about static nested classes in java?
Can we use both this () and super () in a constructor?
Does java support function overloading, pointers, structures, unions or linked lists?
Can we declare array without size in java?
When is the finalize() called?
Explain reverse a linked list iterative solution in java?
What is the different types of functions?
Difference between static binding and dynamic binding?
how to create multithreaded program? Explain different ways of using thread? When a thread is created and started, what is its initial state? Or extending thread class or implementing runnable interface. Which is better? : Java thread