Thursday, October 23, 2025
HomeLanguagesJavaChoiceFormat equals() method in Java with Examples

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)

Parameter: This method takes obj as parameter which is another ChoiceFormat object for comparison.
Return Value: This method returns true if both choice format objects are equal 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)
    {
        // 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");
    }
}


Output: 

Both ChoiceFormat objects are equal

 

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)
    {
        // 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");
    }
}


Output: 

Both ChoiceFormat objects are not equal

 

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

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS