- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java String.equals vs ==
String.equals() compares the content while == checks whether the references are pointing to the same object or not.
Example
See the illustration example below −
public class Tester { public static void main(String[] args) { String test = new String("a"); String test1 = new String("a"); System.out.println(test == test1); System.out.println(test.equals(test1)); } }
Output
false true
- Related Articles
- equals() vs == in Java
- Difference between equals() vs equalsIgnoreCase() in Java
- Java String equals() method.
- Java String equals() method example.
- String compare by equals() method in Java
- Java String comparison, differences between ==, equals, matches, compareTo().
- Java Program to Differentiate String == operator and equals() method
- Java string concat() method vs "+" operator
- Equals(String, String) Method in C#
- Which equals operator (== vs ===) should be used in JavaScript?
- Which equals operator (== vs ===) should be used in JavaScript comparisons
- Integer Equals() method in Java
- LocalTime equals() method in Java
- MonthDay equals() method in Java
- Instant equals() method in Java
- Period equals() method in Java

Advertisements