- Java.util 包類
- Java.util - 首頁
- Java.util - ArrayDeque
- Java.util - ArrayList
- Java.util - Arrays
- Java.util - BitSet
- Java.util - Calendar
- Java.util - Collections
- Java.util - Currency
- Java.util - Date
- Java.util - Dictionary
- Java.util - EnumMap
- Java.util - EnumSet
- Java.util - Formatter
- Java.util - GregorianCalendar
- Java.util - HashMap
- Java.util - HashSet
- Java.util - Hashtable
- Java.util - IdentityHashMap
- Java.util - LinkedHashMap
- Java.util - LinkedHashSet
- Java.util - LinkedList
- Java.util - ListResourceBundle
- Java.util - Locale
- Java.util - Observable
- Java.util - PriorityQueue
- Java.util - Properties
- Java.util - PropertyPermission
- Java.util - PropertyResourceBundle
- Java.util - Random
- Java.util - ResourceBundle
- Java.util - ResourceBundle.Control
- Java.util - Scanner
- Java.util - ServiceLoader
- Java.util - SimpleTimeZone
- Java.util - Stack
- Java.util - StringTokenizer
- Java.util - Timer
- Java.util - TimerTask
- Java.util - TimeZone
- Java.util - TreeMap
- Java.util - TreeSet
- Java.util - UUID
- Java.util - Vector
- Java.util - WeakHashMap
- Java.util 包其他內容
- Java.util - 介面
- Java.util - 異常
- Java.util - 列舉
- Java.util 有用資源
- Java.util - 有用資源
- Java.util - 討論
Java ResourceBundle handleKeySet() 方法
描述
Java ResourceBundle handleKeySet() 方法僅返回此 ResourceBundle 中包含的鍵的 Set。
宣告
以下是 java.util.ResourceBundle.handleKeySet() 方法的宣告
protected Set<String> handleKeySet()
引數
無
返回值
此方法返回此 ResourceBundle 中包含的鍵的 Set
異常
無
從美國區域設定的 ResourceBundle 獲取鍵的列舉示例
以下示例演示了 Java ResourceBundle handleKeySet() 方法的使用。在此示例中,我們擴充套件了 ResourceBundle 類並實現了 handleKeySet() 方法,並獲取了一組鍵作為 HashSet。
package com.tutorialspoint;
import java.util.*;
public class ResourceBundleDemo extends ResourceBundle {
@Override
public Object handleGetObject(String key) {
if (key.equals("hello")) {
return "Hello World!";
} else {
return null;
}
}
@Override
public Enumeration getKeys() {
StringTokenizer key = new StringTokenizer("Hello World!");
return key;
}
protected Set<String> handleKeySet() {
return new HashSet<String>();
}
public static void main(String[] args) {
// create a new ResourceBundle with specified locale
ResourceBundle bundle =
ResourceBundle.getBundle("hello", Locale.US);
// print the keys
Enumeration<String> enumeration = bundle.getKeys();
while (enumeration.hasMoreElements()) {
System.out.println("" + enumeration.nextElement());
}
}
}
輸出
假設您在 CLASSPATH 中有一個名為 hello_en_US.properties 的資原始檔,其內容如下。此檔案將用作我們示例程式的輸入 -
hello = Hello World! bye = Goodbye World! morning = Good Morning World!
讓我們編譯並執行上述程式,這將產生以下結果 -
hello bye morning
從法國區域設定的 ResourceBundle 獲取鍵的列舉示例
以下示例演示了 Java ResourceBundle handleKeySet() 方法的使用。在此示例中,我們擴充套件了 ResourceBundle 類並實現了 handleKeySet() 方法,並獲取了一組鍵作為 HashSet。
package com.tutorialspoint;
import java.util.*;
public class ResourceBundleDemo extends ResourceBundle {
@Override
public Object handleGetObject(String key) {
if (key.equals("hello")) {
return "Bonjour le monde!";
} else {
return null;
}
}
@Override
public Enumeration getKeys() {
StringTokenizer key = new StringTokenizer("Bonjour le monde!");
return key;
}
protected Set<String> handleKeySet() {
return new HashSet<String>();
}
public static void main(String[] args) {
// create a new ResourceBundle with specified locale
ResourceBundle bundle =
ResourceBundle.getBundle("hello", Locale.FRANCE);
// print the keys
Enumeration<String> enumeration = bundle.getKeys();
while (enumeration.hasMoreElements()) {
System.out.println("" + enumeration.nextElement());
}
}
}
輸出
假設您在 CLASSPATH 中有一個名為 hello_en_US.properties 的資原始檔,其內容如下。此檔案將用作我們示例程式的輸入 -
hello = Bonjour le monde! bye = Au revoir le monde! morning = Bonjour le monde!
讓我們編譯並執行上述程式,這將產生以下結果 -
hello bye morning
從德國區域設定的 ResourceBundle 獲取鍵的列舉示例
以下示例演示了 Java ResourceBundle handleKeySet() 方法的使用。在此示例中,我們擴充套件了 ResourceBundle 類並實現了 handleKeySet() 方法,並獲取了一組鍵作為 HashSet。
package com.tutorialspoint;
import java.util.*;
public class ResourceBundleDemo extends ResourceBundle {
@Override
public Object handleGetObject(String key) {
if (key.equals("hello")) {
return "Hallo Welt!";
} else {
return null;
}
}
@Override
public Enumeration getKeys() {
StringTokenizer key = new StringTokenizer("Hallo Welt!");
return key;
}
protected Set<String> handleKeySet() {
return new HashSet<String>();
}
public static void main(String[] args) {
// create a new ResourceBundle with specified locale
ResourceBundle bundle =
ResourceBundle.getBundle("hello", Locale.US);
// print the keys
Enumeration<String> enumeration = bundle.getKeys();
while (enumeration.hasMoreElements()) {
System.out.println("" + enumeration.nextElement());
}
}
}
輸出
假設您在 CLASSPATH 中有一個名為 hello_en_US.properties 的資原始檔,其內容如下。此檔案將用作我們示例程式的輸入 -
hello = Hallo Welt! bye = Auf Wiedersehen Welt! morning = Guten Morgen Welt!
讓我們編譯並執行上述程式,這將產生以下結果 -
hello bye morning