當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java Calendar getAvailableLocales()用法及代碼示例


Calendar類中的clear()方法用於返回該類的getInstance方法的本地化實例上可用的所有語言環境的數組。

用法:

public static Locale[] getAvailableLocales()

參數:該方法不帶任何參數。


返回值:該方法返回所有本地化實例可用的語言環境的數組。

以下示例程序旨在說明Calendar類的getAvailableLocales()方法的用法:
示例1:

// Java Code to illustrate 
// getAvailableLocales() Method 
  
import java.util.*; 
  
public class Calendar_Demo_Locale { 
    public static void main(String args[]) 
    { 
  
        // Creating a locale object 
        Locale loc_arr[] = new Locale[5]; 
  
        // Assigning locales to array 
        loc_arr = Locale.getAvailableLocales(); 
  
        // Displaying the results 
        System.out.println("The first "
                           + "five locales are:"); 
  
        for (int cnt = 0; cnt < 5; cnt++) 
            System.out.println( 
                loc_arr[cnt] 
                    .getISO3Country()); 
    } 
}
輸出:
The first five locales are:

ARE
JOR
SYR
HRV

示例2:

// Java Code to illustrate 
// getAvailableLocales() Method 
  
import java.util.*; 
  
public class Calendar_Demo_Locale { 
    public static void main(String args[]) 
    { 
  
        // Creating a locale object 
        Locale loc_arr[] = new Locale[20]; 
  
        // Assigning locales to array 
        loc_arr = Locale.getAvailableLocales(); 
  
        // Displaying the results 
        System.out.println("The first "
                           + "twenty availables"
                           + " locales are:"); 
  
        for (int cnt = 0; cnt < 20; cnt++) 
            System.out.println( 
                loc_arr[cnt] 
                    .getISO3Country()); 
    } 
}
輸出:
The first twenty availables locales are:

ARE
JOR
SYR
HRV
BEL
PAN
MLT
VEN

TWN




DNK
PRI
VNM
USA
MNE

參考: https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#clone()



相關用法


注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 Calendar getAvailableLocales() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。