top of page

Difference between comparing String using == and .equals() method in Java

Both the equals() method and the == operator are used to compare two objects in Java.

The Java string equals() method, compares two strings and returns true if all characters match in both strings, else returns false. The String equals() method overrides the equals() method of the Object class.


The == operator compares the reference or memory location of objects in a heap, whether they point to the same location or not.

Whenever we create an object using the operator new, it will create a new memory location for that object. So we use the == operator to check memory location or address of two objects are the same or not.

The Java String class equals() method compares the two given strings based on the content of the string. If any character is not matched, it returns false. If all characters are matched, it returns true.




 
 
 

Recent Posts

See All

Comments


MiIT Logo

Company

Contact Us

+1905-487-4880 

5160 Explorer Dr #34, Mississauga,ON L4W 4T7

+1929-743-3199

4466 Buttonwood Ln Lilburn, GA 30047

262 Chapman Rd, STE 240 Newark DE 19702

+44 20 4525 1214

71-75 Shelton Street, Covent Garden, London, United Kingdom WC2H 9JQ

Stay up to date on the latest from MiIT

  • Instagram
  • Facebook
  • http://linkedin.com/company/miittechnologies/about/
  • Whatsapp

© All Content MiIT Technologies Inc.2019 - 2025. All rights reserved.

bottom of page