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


Java 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

相關用法


注:本文由純淨天空篩選整理自 Java.util.ListResourceBundle.getKeys() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。