Collator getAvailableLocales() method in Java with Example
Last Updated :
15 Nov, 2021
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
import java.text.*;
import java.util.*;
import java.io.*;
public class GFG {
public static void main(String[] argv)
{
try {
String simple = "< a< b< c< d" ;
RuleBasedCollator col
= new RuleBasedCollator(simple);
Locale[] locale = col.getAvailableLocales();
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);
}
}
}
|
Output:
Equivalent Locales are
ar_AE
ar_JO
ar_SY
hr_HR
fr_BE
Example 2:
Java
import java.text.*;
import java.util.*;
import java.io.*;
public class GFG {
public static void main(String[] argv)
{
try {
Collator col = Collator.getInstance(Locale.UK);
Locale[] locale = col.getAvailableLocales();
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);
}
}
}
|
Output:
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–
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...