ChoiceFormat equals() method in Java with Examples

The equals() method of java.text.ChoiceFormat class is used to compare between two ChoiceFormat objects and give the Boolean value regarding the comparison.

Syntax:

public boolean equals(Object obj)

Paramter: This method takes obj as parameter which is the another ChoiceFormat object for comparison.



Return Value: This method returns true if the both choice format objects are equal otherwise false.

Below are the examples to illustrate the equals() method:

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate equals() method
  
import java.text.*;
import java.util.*;
import java.io.*;
  
public class GFG {
    public static void main(String[] argv)
    {
        // creating and initializing ChoiceFormat
        ChoiceFormat cf1
            = new ChoiceFormat(
                "4#wed| 5#thu | 6#fri | 7#sat");
  
        // creating and initializing ChoiceFormat
        ChoiceFormat cf2
            = new ChoiceFormat(
                "4#wed| 5#thu | 6#fri | 7#sat");
  
        // compare cf1 and cf2
        // using equals() method
        boolean status = cf1.equals(cf2);
  
        // display the result
        if (status)
            System.out.println("Both ChoiceFormat"
                               + " objects are equal");
        else
            System.out.println("Both ChoiceFormat "
                               + "objects are not equal");
    }
}

chevron_right


Output:

Both ChoiceFormat objects are equal

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate equals() method
  
import java.text.*;
import java.util.*;
import java.io.*;
  
public class GFG {
    public static void main(String[] argv)
    {
        // creating and initializing ChoiceFormat
        ChoiceFormat cf1
            = new ChoiceFormat(
                "1#sun| 2#mon | 3#tues | 4#wed");
  
        // creating and initializing ChoiceFormat
        ChoiceFormat cf2
            = new ChoiceFormat(
                "4#wed| 5#thu | 6#fri | 7#sat");
  
        // compare cf1 and cf2
        // using equals() method
        boolean status = cf1.equals(cf2);
  
        // display the result
        if (status)
            System.out.println("Both ChoiceFormat"
                               + " objects are equal");
        else
            System.out.println("Both ChoiceFormat "
                               + "objects are not equal");
    }
}

chevron_right


Output:

Both ChoiceFormat objects are not equal

Reference: https://docs.oracle.com/javase/9/docs/api/java/text/ChoiceFormat.html#applyPattern-java.lang.String-



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.