FieldPosition toString() method in Java with Example Last Updated : 16 Jan, 2020 Comments Improve Suggest changes Like Article Like Report The toString() method of java.text.FieldPosition class is used to represent the field position object in the form of string. Syntax: public String toString() Parameter: This method does not accepts any argument as parameter. Return Value: This method returns the string representation of this FieldPosition object. Below are the examples to illustrate the toString() method: Example 1: Java // Java program to demonstrate // toString() 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 = new FieldPosition( MessageFormat.Field.ARGUMENT); // getting the String representation // of this FieldPosition Object // using toString() method String str = pos.toString(); // display result System.out.println("FieldPosition :- " + str); } catch (ClassCastException e) { System.out.println("Exception thrown : " + e); } } } Output: FieldPosition :- java.text.FieldPosition[field=-1, attribute=java.text.MessageFormat$Field(message argument field), beginIndex=0, endIndex=0] Example 2: Java // Java program to demonstrate // toString() 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 = new FieldPosition( DateFormat.Field.AM_PM); // getting the String representation // of this FieldPosition Object // using toString() method String str = pos.toString(); // display result System.out.println("FieldPosition :- " + str); } catch (ClassCastException e) { System.out.println("Exception thrown : " + e); } } } Output: FieldPosition :- java.text.FieldPosition[field=-1, attribute=java.text.DateFormat$Field(am pm), beginIndex=0, endIndex=0] Reference: https://docs.oracle.com/javase/9/docs/api/java/text/FieldPosition.html#toString-- Comment More infoAdvertise with us Next Article Class toString() method in Java with Examples R rohitprasad3 Follow Improve Article Tags : Java Java-Functions Java-FieldPosition Practice Tags : Java Similar Reads Field toString() method in Java with Examples The toString() method of java.lang.reflect.Field is used to get a string describing this Field. The format of the returned string is the access modifiers for the field, if any, followed by the field type, followed by a space, followed by the fully-qualified name of the class declaring the field, fol 3 min read Field toGenericString() method in Java with Examples The toGenericString() method of java.lang.reflect.Field is used to return a string which represents this Field, including its generic type. The format of the string is the access modifiers for the field, if any, followed by the generic field type, followed by a space, followed by the fully-qualified 2 min read Class toString() method in Java with Examples The toString() method of java.lang.Class class is used to convert the instance of this Class to a string representation. This method returns the formed string representation. Syntax: public String toString() Parameter: This method does not accept any parameter. Return Value: This method returns the 1 min read Class toString() method in Java with Examples The toString() method of java.lang.Class class is used to convert the instance of this Class to a string representation. This method returns the formed string representation. Syntax: public String toString() Parameter: This method does not accept any parameter. Return Value: This method returns the 1 min read Class toString() method in Java with Examples The toString() method of java.lang.Class class is used to convert the instance of this Class to a string representation. This method returns the formed string representation. Syntax: public String toString() Parameter: This method does not accept any parameter. Return Value: This method returns the 1 min read Year toString() method in Java with Examples The toString() method of Year class in Java is used to return the string representation of this Year object. Syntax: public String toString() Parameter: This method does not accepts any parameter. Return Value: It returns the string representation of this Year object. Below programs illustrate the t 1 min read Like