FieldPosition equals() method in Java with Example Last Updated : 20 Dec, 2022 Comments Improve Suggest changes Like Article Like Report 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 // Java program to demonstrate // equals() method import java.text.*; import java.util.*; import java.io.*; public class GFG { public static void main(String[] argv) { try { // Creating and initializing // new FieldPosition Object FieldPosition pos_1 = new FieldPosition( DateFormat.Field.AM_PM); // Creating and initializing // new FieldPosition Object FieldPosition pos_2 = new FieldPosition( DateFormat.Field.AM_PM); // compare both object // using equals() method boolean i = pos_1.equals(pos_2); // display result 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 // Java program to demonstrate // equals() method import java.text.*; import java.util.*; import java.io.*; public class GFG { public static void main(String[] argv) { try { // Creating and initializing // new FieldPosition Object FieldPosition pos_1 = new FieldPosition( DateFormat.Field.AM_PM); // Creating and initializing // new FieldPosition Object FieldPosition pos_2 = new FieldPosition( MessageFormat.Field.ARGUMENT); // compare both object // using equals() method boolean i = pos_1.equals(pos_2); // display result 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- Comment More infoAdvertise with us Next Article Field equals() method in Java with Examples R rohitprasad3 Follow Improve Article Tags : Java Java-Functions Java-text package Java-FieldPosition Practice Tags : Java Similar Reads Field equals() method in Java with Examples The equals() method of java.lang.reflect.Field is used to compare two field objects. This method compares two field objects and returns true if both objects are equal otherwise false. The two Field objects are considered equal if and only if when they were declared by the same class and have the sam 3 min read Field equals() method in Java with Examples The equals() method of java.lang.reflect.Field is used to compare two field objects. This method compares two field objects and returns true if both objects are equal otherwise false. The two Field objects are considered equal if and only if when they were declared by the same class and have the sam 3 min read Field equals() method in Java with Examples The equals() method of java.lang.reflect.Field is used to compare two field objects. This method compares two field objects and returns true if both objects are equal otherwise false. The two Field objects are considered equal if and only if when they were declared by the same class and have the sam 3 min read Field equals() method in Java with Examples The equals() method of java.lang.reflect.Field is used to compare two field objects. This method compares two field objects and returns true if both objects are equal otherwise false. The two Field objects are considered equal if and only if when they were declared by the same class and have the sam 3 min read Field equals() method in Java with Examples The equals() method of java.lang.reflect.Field is used to compare two field objects. This method compares two field objects and returns true if both objects are equal otherwise false. The two Field objects are considered equal if and only if when they were declared by the same class and have the sam 3 min read Float equals() method in Java with examples The equals() method in Float Class is a built-in function in java that compares this object to the specified object. The result is true if and only if the argument is not null and is a Float object that contains the same double value as this object. It returns false if both the objects are not same. 3 min read Like