ChoiceFormat equals() method in Java with Examples
Last Updated :
27 Jan, 2023
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
import java.text.*;
import java.util.*;
import java.io.*;
public class GFG {
public static void main(String[] argv)
{
ChoiceFormat cf1
= new ChoiceFormat(
"4#wed| 5#thu | 6#fri | 7#sat" );
ChoiceFormat cf2
= new ChoiceFormat(
"4#wed| 5#thu | 6#fri | 7#sat" );
boolean status = cf1.equals(cf2);
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
import java.text.*;
import java.util.*;
import java.io.*;
public class GFG {
public static void main(String[] argv)
{
ChoiceFormat cf1
= new ChoiceFormat(
"1#sun| 2#mon | 3#tues | 4#wed" );
ChoiceFormat cf2
= new ChoiceFormat(
"4#wed| 5#thu | 6#fri | 7#sat" );
boolean status = cf1.equals(cf2);
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-
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...