Monday, November 18, 2024
Google search engine
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 Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments