Collator equals(Object) method in Java with Example Last Updated : 23 Jan, 2023 Comments Improve Suggest changes Like Article Like Report 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 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 new simple rule String simple = "< a< b< c< d"; // Creating and initializing // new RuleBasedCollator Object RuleBasedCollator col_1 = new RuleBasedCollator(simple); // Creating and initializing // Collator Object Collator col_2 = Collator.getInstance(Locale.US); // compare both object // using equals() method boolean i = col_1.equals(col_2); // display result if (i) System.out.println(col_1 + " is equal to " + col_2); else System.out.println(col_1 + " is not equal to " + col_2); } catch (ClassCastException e) { System.out.println("Exception thrown : " + e); } catch (ParseException e) { System.out.println("Exception thrown : " + e); } } } Output: java.text.RuleBasedCollator@5eb2e1c2 is not equal to java.text.RuleBasedCollator@289747d6 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_1 = Collator.getInstance(Locale.UK); // Creating and initializing // Collator Object Collator col_2 = Collator.getInstance(Locale.US); // compare both object // using equals() method boolean i = col_1.equals(col_2); // display result if (i) System.out.println(col_1 + " is equal to " + col_2); else System.out.println(col_1 + " is not equal to " + col_2); } catch (ClassCastException e) { System.out.println("Exception thrown : " + e); } } } Output: java.text.RuleBasedCollator@289747d6 is equal to java.text.RuleBasedCollator@289747d6 Reference: https://docs.oracle.com/javase/9/docs/api/java/text/Collator.html#equals-java.lang.Object- Comment More infoAdvertise with us Next Article Collator equals(Object) method in Java with Example R rohitprasad3 Follow Improve Article Tags : Java Java-Functions Java-text package Java-Collator Practice Tags : Java Similar Reads Collator equals(String, String) method in Java with Example 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 2 min read Collator compare(Object, Object) method in Java with Example The compare() method of java.text.Collator class is used to compare the strength of two objects and it will return 0, positive and negative value as an output according to the result . Syntax: public int compare(Object o1, Object o2) Parameter: This method takes two objects between which comparison 2 min read Character.equals() method in Java with examples The java.lang.Character.equals() is a function in Java which compares this object against the specified object. If the argument is not null then the result is true and is a Character object that represents the same char value as this object. Syntax: public boolean equals(Object obj) Parameters: The 2 min read Constructor equals() method in Java with Examples The constructor class provides information about a single constructor for a class and it also provides access to that constructor. The equals() method of java.lang.reflect.Constructor is used to compare this Constructor against the passed object. If the objects are the same then the method returns t 2 min read Charset equals() method in Java with Examples The equals() method is a built-in method of the java.nio.charset checks if a given object of charset is equal to another given object of the charset. Two charsets are considered equal if, and only if, they have the same canonical names. A charset is never equal to any other type of object. Syntax: p 2 min read Like