Java.util.ListResourceBundle.getKeys() 方法
描述
java.util.ListResourceBundle.getKeys() 方法返回包含在此 ResourceBundle 及其父包中的键的枚举。
声明
以下是 java.util.ListResourceBundle.getKeys() 方法的声明
public Enumeration<String> getKeys()
参数
NA
返回值
此方法返回包含在此 ResourceBundle 及其父包中的键的枚举。
异常
NA
示例
下面的例子展示了 java.util.ListResourceBundle.getKeys() 方法的使用。
package com.tutorialspoint;
import java.util.*;
// create a class that extends to ListResourceBundle
class MyResources extends ListResourceBundle {
// get contents must be implemented
protected Object[][] getContents() {
return new Object[][] {
{"hello", "Hello World!"},
{"bye", "Goodbye World!"},
{"goodnight", "Goodnight World!"}
};
}
}
public class ListResourceBundleDemo {
public static void main(String[] args) {
// create a new MyResources instance
MyResources mr = new MyResources();
// get the keys
Enumeration<String> enumeration = mr.getKeys();
// print the keys
while (enumeration.hasMoreElements()) {
System.out.println("" + enumeration.nextElement());
}
}
}
让我们编译并运行上面的程序,这将产生以下结果 −
hello goodnight bye

