Java String equals() Method Last Updated : 23 Dec, 2024 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 Comment More infoAdvertise with us Next Article Java String equals() Method D d_singh Follow Improve Article Tags : Java Java Programs Java-Strings Practice Tags : JavaJava-Strings Similar Reads EnumMap equals() Method in Java with Examples The Java.util.EnumMap.equals(obj) in Java is used to compare the passed object with this EnumMap for the equality. It must be kept in mind that the object passed must be a map of the same type as the EnumMap.Syntax: boolean equals(Object obj) Parameter: The method takes one parameter obj of Object t 2 min read equals() and deepEquals() Method to Compare two Arrays in Java Arrays. equals() method does not compare recursively if an array contains another array on other hand Arrays. deepEquals() method compare recursively if an array contains another array. Arrays.equals(Object[], Object[]) Syntax : public static boolean equals(int[] a, int[] a2) Parameters : a - one ar 3 min read Check if Two Integers are Equal or Not in Java Checking two integers equal or not in Java is done by various approaches. Arithmetic operatorComparison OperatorsString functionsXOR operatorComplement (~) and bit-wise (&) operator Example Input: FirstNumber = 15 SecondNumber= 15 Output: Numbers are same Input: FirstNumber = 15 SecondNumber= 25 2 min read Java Program to Compare Two Objects An object is an instance of a class that has its state and behavior. In java, being object-oriented, it is always dynamically created and automatically destroyed by the garbage collector as the scope of the object is over. Illustration: An example to illustrate an object of a class: Furniture chair= 6 min read Comparing two ArrayList In Java Java provides a method for comparing two Array List. The ArrayList.equals() is the method used for comparing two Array List. It compares the Array lists as, both Array lists should have the same size, and all corresponding pairs of elements in the two Array lists are equal. Example: Input : ArrayLis 2 min read Like