FieldPosition equals() method in Java with Example
Last Updated :
20 Dec, 2022
The equals() method of java.text.FieldPosition class is used to check if both the FieldPosition objects are same or not.
Syntax:
public boolean equals(Object obj)
Parameter: This method takes FieldPosition objects which will be compared with the current FieldPosition object.
Return Value: if both the FieldPosition objects are equal to each other then it will return true 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)
{
try {
FieldPosition pos_1
= new FieldPosition(
DateFormat.Field.AM_PM);
FieldPosition pos_2
= new FieldPosition(
DateFormat.Field.AM_PM);
boolean i = pos_1.equals(pos_2);
if (i)
System.out.println(
"pos_1 is equals to pos_2" );
else
System.out.println(
"pos_1 is not equal to pos_2" );
}
catch (ClassCastException e) {
System.out.println( "Exception thrown : " + e);
}
}
}
|
Output:
pos_1 is equals to pos_2
Example 2:
Java
import java.text.*;
import java.util.*;
import java.io.*;
public class GFG {
public static void main(String[] argv)
{
try {
FieldPosition pos_1
= new FieldPosition(
DateFormat.Field.AM_PM);
FieldPosition pos_2
= new FieldPosition(
MessageFormat.Field.ARGUMENT);
boolean i = pos_1.equals(pos_2);
if (i)
System.out.println(
"pos_1 is equals to pos_2" );
else
System.out.println(
"pos_1 is not equal to pos_2" );
}
catch (ClassCastException e) {
System.out.println( "Exception thrown : " + e);
}
}
}
|
Output:
pos_1 is not equal to pos_2
Reference: https://docs.oracle.com/javase/9/docs/api/java/text/FieldPosition.html#equals-java.lang.Object-
Share your thoughts in the comments
Please Login to comment...