The equals() method of java.text.MessageFormat class is used to check if both the MessageFormat objects are same or not.
Syntax:
public boolean equals(Object obj)
Parameter: This method takes MessageFormat objects which will be compared with the current MessageFormat object.
Return Value: if both the MessageFormat objects are equal to each other than it will return true otherwise false.
Below are the examples to illustrate the equals() method:
Example 1:
// 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 MessageFormat MessageFormat mf1 = new MessageFormat("{0, date, #}, {1, time, #}, {0, number}"); // creating and initializing MessageFormat MessageFormat mf2 = new MessageFormat("{0, date, #}, {1, time, #}, {0, number}"); // compare both object // using equals() mehtod boolean i = mf1.equals(mf2); // display result if (i) System.out.println( "mf1 is equals to mf2"); else System.out.println( "mf1 is not equal to mf2"); } catch (ClassCastException e) { System.out.println("Exception thrown : " + e); } } } |
mf1 is equals to mf2
Example 2:
// 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 MessageFormat MessageFormat mf1 = new MessageFormat("{0, date, #}, {1, time, #}, {0, number}"); // creating and initializing MessageFormat MessageFormat mf2 = new MessageFormat("{0, date, #}, {0, time, #}, {0, number}"); // compare both object // using equals() mehtod boolean i = mf1.equals(mf2); // display result if (i) System.out.println( "mf1 is equals to mf2"); else System.out.println( "mf1 is not equal to mf2"); } catch (ClassCastException e) { System.out.println("Exception thrown : " + e); } } } |
mf1 is not equal to mf2
Reference: https://docs.oracle.com/javase/9/docs/api/java/text/MessageFormat.html#equals-java.lang.Object-
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- MessageFormat toPattern() method in Java with Example
- MessageFormat applyPattern() method in Java with Example
- MessageFormat format() method in Java with Example : Set - 1
- MessageFormat format() method in Java with Example : Set - 2
- MessageFormat formatToCharacterIterator() method in Java with Example
- MessageFormat getFormats() method in Java with Example
- MessageFormat getFormatsByArgumentIndex() method in Java with Example
- MessageFormat getLocale() method in Java with Example
- MessageFormat hashCode() method in Java with Example
- MessageFormat parse() method in Java with Example : Set - 1
- MessageFormat parse() method in Java with Example : Set - 2
- MessageFormat parseObject() method in Java with Example
- MessageFormat setFormat() method in Java with Example
- MessageFormat setFormatByArgumentIndex() method in Java with Example
- MessageFormat setFormats() method in Java with Example
- MessageFormat setFormatsByArgumentIndex() method in Java with Example
- MessageFormat setLocale() method in Java with Example
- Stack equals() method in Java with Example
- LinkedHashSet equals() method in Java with Example
- AbstractSequentialList equals() method in Java with Example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

