Java String equals() Method Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report String equals() method in Java compares the content of two strings. It compares the value's character by character, irrespective of whether two strings are stored in the same memory location. The String equals() method overrides the equals() method of the object class. false if any of the characters are not matched. true if all characters are matched in the Strings. Example: Basic Comparision Java class Geeks { public static void main(String[] args) { String str1 = "Learn Java"; String str2 = "Learn Java"; String str3 = "Learn Kotlin"; boolean result; // Comparing str1 with str2 result = str1.equals(str2); System.out.println(result); // Comparing str1 with str3 result = str1.equals(str3); System.out.println(result); // Comparing str3 with str1 result = str3.equals(str1); System.out.println(result); } } Outputtrue false false Syntaxstring.equals(object) Return Type: The return type for the equals method is Boolean.Case-Insensitive Comparison of StringsIt compares the difference between uppercase and lowercase characters. We compare three strings using the equalsIgnoreCase() method of str1, str2, and str3 to check case-insensitive comparison.Example: Java // Working equalsIgnoreCase() Method import java.io.*; public class Geeks { public static void main(String[] args) { // Define three strings String str1 = "Hello"; String str2 = "hello"; String str3 = "WORLD"; // Comparison between str1 and str2 System.out.println("str1.equals(str2): "+ str1.equals(str2)); // Comparison between str1 and str2(Case Insensitive) System.out.println("str1.equalsIgnoreCase(str2): "+ str1.equalsIgnoreCase(str2)); // Comparison between str2 and str3 System.out.println("str2.equalsIgnoreCase(str3): "+ str2.equalsIgnoreCase(str3)); } } Outputstr1.equals(str2): false str1.equalsIgnoreCase(str2): true str2.equalsIgnoreCase(str3): false Create Quiz Comment D d_singh Follow 0 Improve D d_singh Follow 0 Improve Article Tags : Java Java Programs Java-Strings Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like