Home » Java programming language

Java Calendar getAvailableLocales() Method with Example

Calendar Class getAvailableLocales() method: Here, we are going to learn about the getAvailableLocales() method of Calendar Class with its syntax and example.
Submitted by Preeti Jain, on February 02, 2020

Calendar Class getAvailableLocales() method

  • getAvailableLocales() method is available in java.util package.
  • getAvailableLocales() method is used to return Locale[] (an array of Locale) for which to return localized instances by using getInstance() method of this class.
  • getAvailableLocales() method is a static method, it is accessible with the class name and if we try to access the method with the class object then we will not get an error.
  • getAvailableLocales() method does not throw an exception at the time of returning localized instances.

Syntax:

    public static Locale[] getAvailableLocales();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is Locale[], it returns Locale array for which to return existing localized instances.

Example:

// Java Program to demonstrate the example of
// void Locale[] getAvailableLocales() method of 
// Calendar

import java.util.*;

public class GetAvailableLocales {
    public static void main(String[] args) {
        // Instantiating a Calendar object
        Calendar ca = Calendar.getInstance();

        // Display current calendar
        System.out.println("ca: " + ca.getTime());

        // Creating a Locale object
        Locale[] lo = new Locale[5];

        // By using getAvailableLocales() method is 
        // to get the current locales
        lo = Locale.getAvailableLocales();

        System.out.println("First four locales: ");
        for (int i = 0; i < 5; ++i)
            System.out.println(lo[i]);
    }
}

Output

ca: Sun Feb 02 09:43:58 GMT 2020
First four locales: 

nn
ar_JO
bg
kea


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.