The getAvailableLocales() method of java.text.Collator class is used to get the all available locales which come under the passed Locales instance during the initializing of Collator object.
Syntax:
public static Locale[] getAvailableLocales()
Parameter: This method does not accept any parameter.
Return Value: This method returns all the available locales which come under this instance.
Below are the examples to illustrate the getAvailableLocales() method:
Example 1:
Java
// Java program to demonstrate // getAvailableLocales() method import java.text.*; import java.util.*; import java.io.*; public class GFG { public static void main(String[] argv) { try { // Creating and initializing new simple rule String simple = "< a< b< c< d" ; // Creating and initializing // new RuleBasedCollator Object RuleBasedCollator col = new RuleBasedCollator(simple); // getting all the available locale // using getAvailableLocales() method Locale[] locale = col.getAvailableLocales(); // display result System.out.println( "Equivalent Locales are " ); for ( int i = 1 ; i <= 5 ; i++) System.out.println(locale[i]); } catch (ClassCastException e) { System.out.println( "Exception thrown : " + e); } catch (ParseException e) { System.out.println( "Exception thrown : " + e); } } } |
Equivalent Locales are ar_AE ar_JO ar_SY hr_HR fr_BE
Example 2:
Java
// Java program to demonstrate // getAvailableLocales() method import java.text.*; import java.util.*; import java.io.*; public class GFG { public static void main(String[] argv) { try { // Creating and initializing Collator Object Collator col = Collator.getInstance(Locale.UK); // getting all the available locale // using getAvailableLocales() method Locale[] locale = col.getAvailableLocales(); // display result System.out.println( "Equivalent Locales are " ); for ( int i = 6 ; i <= 10 ; i++) System.out.println(locale[i]); } catch (ClassCastException e) { System.out.println( "Exception thrown : " + e); } } } |
Equivalent Locales are es_PA es_VE mt_MT bg zh_TW
Reference: https://docs.oracle.com/javase/9/docs/api/java/text/Collator.html#getAvailableLocales–