java.util.ResourceBundle.containsKey(String key)%uA0方法确定给定键是否包含在此ResourceBundle或其父包。
声明
以下是java.util.ResourceBundle.containsKey()方法的声明
public boolean containsKey(String key)
参数
-
key%uA0-- 资源键
返回值
如果给定的键包含在此ResourceBundle或其父包此方法返回true否则为false。
异常
-
NullPointerException%uA0-- 如果%uA0key 为%uA0null
例子
下面的示例演示java.util.ResourceBundle.containsKey()方法的用法。
package com.yiibai import java.util.Locale import java.util.ResourceBundle public class ResourceBundleDemo { public static void main(String[] args) { // create a new ResourceBundle with specified locale ResourceBundle bundle = ResourceBundle.getBundle("hello", Locale.US) // print the text assigned to key "hello" System.out.println("" + bundle.getString("hello")) // check if the bundle contains "bye" key System.out.println("" + bundle.containsKey("bye")) // check if the bundle contains "hello" key System.out.println("" + bundle.containsKey("hello")) } }
假设在你的CLASSPATH中资源文件hello_en_US.properties可用,%uA0以下内容。该文件将被用作输入到示例程序:
hello=Hello World!
让我们来编译和运行上面的程序,这将产生以下结果:
Hello World! false true