ChoiceFormat getFormats() method in Java with Examples6 Jan 2025 | 2 min read The 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] |
Java is an object-oriented, class-based programming language. The language is designed to have as few dependencies implementations as possible. The intention of using this language is to give relief to the developers from writing codes for every platform. The term WORA, write once and run...
10 min read
Image processing is a major head in the digital media and content management department, and its applications vary from simple photo editing to advanced computer vision tasks. One of the typical applications in image processing is watermarking: superimposing a recognizable logo, text, or image on...
7 min read
Pairwise swapping of a linked list involves swapping adjacent nodes in the list without changing the values inside the nodes. The goal is to rearrange the list such that every two consecutive nodes exchange their positions while maintaining the overall sequence of the list. This operation...
12 min read
In 1997, Sun Microsystems and IBM decided to solve the problem of access-enabling software. Their aim was to develop such an accessibility API that application developers could implement on Java class libraries to make applications accessible. As the result, Sun Microsystems wrote the accessibility API and...
3 min read
The passing and returning of objects between methods is a basic feature of Java programming and is essential to creating reliable, modular programs. In this section, we will discuss passing and returning objects in Java, exploring different kinds and methods along the way and offering complete...
5 min read
In Java programming, determining if two matrices are mirror images of each other involves comparing corresponding elements in reverse order. A matrix is considered a mirror image of another if its rows or columns are reversed versions of the corresponding rows or columns in the...
6 min read
? There are different versions of Java is available. Some of the applications generally require different version because of compatibility problems. In this section, we will learn how to check JRE version in Windows using CMD. A version string contains a version number optionally followed by pre-release and...
2 min read
Reading PDF file through a Java program is not the same as reading a text file. The way of reading a PDF file is a bit different. JDK does not provide any class to read PDF file. In order to read a PDF file, we depend...
4 min read
Diffie-Hellman algorithm is one of the most important algorithms used for establishing a shared secret. At the time of exchanging data over a public network, we can use the shared secret for secret communication. We use an elliptic curve for generating points and getting a secret...
4 min read
Java's generics offer a potent means of constructing classes, interfaces, and methods that handle various types while maintaining type safety. The versatility is further increased by wildcards in generics, which let you design more adaptable and reusable code. The upper bounded wildcard is one type of...
4 min read
We request you to subscribe our newsletter for upcoming updates.
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