- 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() method example.
The equals() method of the String class accepts a String as a parameter and it compares the current string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.
Example
import java.lang.*; public class StringDemo { public static void main(String[] args) { String str1 = new String("sachin tendulkar"); String str2 = new String("amrood admin"); String str3 = new String("amrood admin"); // checking for equality boolean retval1 = str2.equals(str1); boolean retval2 = str2.equals(str3); // prints the return value System.out.println("str2 is equal to str1 = " + retval1); System.out.println("str2 is equal to str3 = " + retval2); } }
Output
str2 is equal to str1 = false str2 is equal to str3 = true
Advertisements