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 anti pattern in cyber security?
what is meant by Byte code concept in Java?
Explain what pure virtual function is?
What is string in java is it a data type?
What does serializing data mean?
What is Major and importance difference between for and foreach loop ?
Differentiate between vector and array list.
What is the base class of all exception classes?
What is final int?
What is final access modifier in java?
What is object class in java?
What is Applet Stub Interface ?
What is appletviewer?
how we can make a write-only class in java?
Is empty string in java?