1.

Explain What Is The Use Of == And Equals() Method?

Answer»

The == operator COMPARE WHETHER two object references are refer to the same INSTANCE or not.The equals() METHOD compare the characters(contents) of two String object.

EXAMPLE:

String a="Hai"; 
String b="Hai";
String c=new String("Hai");
System.out.println(a==b); //True
System.out.println(a==c); //False
System.out.println(a.equals(b)); //True
System.out.println(a.equals(c)); //True

The == operator compare whether two object references are refer to the same instance or not.The equals() method compare the characters(contents) of two String object.

Example:

String a="Hai"; 
String b="Hai";
String c=new String("Hai");
System.out.println(a==b); //True
System.out.println(a==c); //False
System.out.println(a.equals(b)); //True
System.out.println(a.equals(c)); //True



Discussion

No Comment Found