当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java Java.util.ListResourceBundle.handleKeySet()用法及代码示例



描述

这个java.util.ListResourceBundle.handleKeySet()方法返回一组仅包含在此 ResourceBundle 中的键。

声明

以下是声明java.util.ListResourceBundle.handleKeySet()方法

protected Set<String> handleKeySet()

参数

keyâˆ' 所需对象的键

返回值

此方法返回一组仅包含在此 ResourceBundle 中的键

异常

NA

示例

下面的例子展示了 java.util.ListResourceBundle.handleKeySet() 方法的用法。

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!"}
      };
   }
   
   protected Set<String> handleKeySet() {
      return new HashSet<String>();
   }
}

public class ListResourceBundleDemo {
   public static void main(String[] args) {

      // create a new MyResources instance
      MyResources mr = new MyResources();

      // get the object for key hello
      System.out.println("" + mr.getString("hello"));
   }
}

让我们编译并运行上面的程序,这将产生以下结果——

Hello World!

相关用法


注:本文由纯净天空筛选整理自 Java.util.ListResourceBundle.handleKeySet() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。