Java.util.ListResourceBundle.getKeys() Method

Advertisements


Description

The java.util.ListResourceBundle.getKeys() method returns an Enumeration of the keys contained in this ResourceBundle and its parent bundles.

Declaration

Following is the declaration for java.util.ListResourceBundle.getKeys() method

public Enumeration<String> getKeys()

Parameters

  • NA

Return Value

This method returns an Enumeration of the keys contained in this ResourceBundle and its parent bundles.

Exception

  • NA

Example

The following example shows the usage of java.util.ListResourceBundle.getKeys() method.

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());
      }

   }
}

Let us compile and run the above program, this will produce the following result:

hello
goodnight
bye



Advertisements
Advertisements