Collator equals(String, String) method in Java with Example Last Updated : 30 Jan, 2023 Comments Improve Suggest changes Like Article Like Report The equals() method of java.text.Collator class is used to check if both strings are identical or not. Syntax: public boolean equals(String source, String target) Parameter: This method takes two strings between which comparison is going to take place. Return Value: if both strings are equal to each other then it will return true otherwise false. Below are the examples to illustrate the equals() method: Example 1: Java // Java program to demonstrate // equals() method import java.text.*; import java.util.*; import java.io.*; public class GFG { public static void main(String[] argv) { try { // Creating and initializing // Collator Object Collator col = Collator.getInstance(); // Creating an initializing // object for comparison String obj1 = "a"; // Creating an initializing // Object for comparison String obj2 = "A"; // compare both object // using equals() method boolean i = col.equals(obj1, obj2); // display result if (i) System.out.println(obj1 + " is equal to " + obj2); else System.out.println(obj1 + " is not equal to " + obj2); } catch (ClassCastException e) { System.out.println("Exception thrown : " + e); } } } Output: a is not equal to A Example 2: Java // Java program to demonstrate // equals() method import java.text.*; import java.util.*; import java.io.*; public class GFG { public static void main(String[] argv) { try { // Creating and initializing // Collator Object Collator col = Collator.getInstance(); // Creating an initializing // object for comparison String obj1 = "a"; // Creating an initializing // Object for comparison String obj2 = "a"; // compare both object // using equals() method boolean i = col.equals(obj1, obj2); // display result if (i) System.out.println(obj1 + " is equal to " + obj2); else System.out.println(obj1 + " is not equal to " + obj2); } catch (ClassCastException e) { System.out.println("Exception thrown : " + e); } } } Output: a is equal to a Reference: https://docs.oracle.com/javase/9/docs/api/java/text/Collator.html#equals-java.lang.String-java.lang.String- Comment More infoAdvertise with us Next Article Collator equals(String, String) method in Java with Example rohitprasad3 Follow Improve Article Tags : Java Java-Functions Java-text package Java-Collator Practice Tags : Java Similar Reads Collator compare(String, String) method in Java with Example The compare() method of java.text.Collator class is used to compare the strength of two string and it will return 0, positive and negative values as an output according to the result. Syntax: public abstract int compare(String source, String target) Parameter: This method takes two strings between w 2 min read Collator equals(Object) method in Java with Example The equals() method of java.text.Collator class is used to check if both the Collator objects are same or not. Syntax: public boolean equals(Object that) Parameter: This method takes two Collator objects between which comparison is going to take place.Return Value: if both Collator objects are equal 2 min read StringWriter equals() method in Java with Example The Java.io.StringWriter.equals(Object obj) method of StringWriter class in Java is used to check whether the two instances of StringWriter are equal or not. It returns a boolean stating whether they are equal or not. Signature: public boolean equals(StringWriter second_StringWriter) Syntax: first_S 2 min read Java String contentEquals() Method with Examples contentEquals() method of String class is used to compare the strings. There are two types of contentEquals method available in java.lang.String with different parameters: contentEquals(StringBuffer sb)contentEquals(CharSequence cs)1. contentEquals(StringBuffer sb): contentEquals(StringBuffer sb) me 3 min read TreeSet equals() method in Java with Example The equals() method of java.util.TreeSet class is used to compare the specified object with this set for equality. Returns true if and only if the specified object is also a set, both sets have the same size, and all corresponding pairs of elements in the two sets are equal. (Two elements e1 and e2 2 min read Like