ChoiceFormat getFormats() method in Java with Examples
Last Updated :
14 Feb, 2022
The getFormats() method of java.text.ChoiceFormat class is used to get the attached format to ChoiceFormat object in time of initialization. It provides the array of specified type.
Syntax:
public Object[] getFormats()
Parameter: This method does not accept any parameter.
Return Value: This method returns an array of the specified type which is the format attached to the ChoiceFormat object.
Below are the examples to illustrate the getFormats() 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" );
String[] format
= (String[])cf1.getFormats();
System.out.print( "Format: "
+ Arrays.toString(format));
}
}
|
Output:
Format: [wed, thu , fri , sat]
Example 2:
Java
import java.text.*;
import java.util.*;
import java.io.*;
public class GFG {
public static void main(String[] argv)
{
double [] limit = { 1 , 2 , 3 , 4 };
String[] format
= { "add" , "sub" ,
"multiply" , "divide" };
ChoiceFormat cf
= new ChoiceFormat(limit, format);
String[] format
= (String[])cf.getFormats();
System.out.print( "Format: "
+ Arrays.toString(format));
}
}
|
Output:
Format: [add, sub, multiply, divide]
Reference: https://docs.oracle.com/javase/9/docs/api/java/text/ChoiceFormat.html#getFormats–
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...