ChoiceFormat getFormats() method in Java with ExamplesThe java.text.ChoiceFormat is a class containing a getFormats() as a function. When the ChoiceFormat object is being initialized, the ChoiceFormat class is utilized to retrieve the connected format. It provides an array of the specified type. Syntax: Parameter: There are no parameters accepted by this method. Return Value: The format that corresponds to the ChoiceFormat object is returned by this function as an array of the given type. Example1:The following Java program shows how to retrieve the string formats associated with numerical limits by using the getFormats() method of the ChoiceFormat class. The program initializes a ChoiceFormat object with a pattern that maps integers 0 through 5 to the months of January through June. Subsequently, the getFormats() method is used, returning an array containing the format strings specified within the ChoiceFormat entity. Arrays.toString() is used to cast these format strings to a String[] array before printing them. Implementation: FileName: GetFormatExample1.java Output: The get Format is : [JANUARY , FEBRUARY , MARCH , APRIL , MAY , JUNE] Example2:The Java program that is provided shows how to map numerical limitations to string formats and retrieve these formats using the ChoiceFormat class. ChoiceFormat is initialized by the application using arrays for the respective string formats ("JANUARY", "FEBRUARY", "MARCH", "APRIL") and numerical limitations (1, 2, 3, 4). The array of formats linked to the ChoiceFormat object is then obtained using the getFormats() function. For ease of use, this array, which was initially of type Object[], is transformed into a String[]. Implementation: FileName: GetFormatExample2.java Output: The get Format is : [JANUARY, FEBRUARY, MARCH, APRIL] |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India