Home » Java programming language

Java ResourceBundle getKeys() Method with Example

ResourceBundle Class getKeys() method: Here, we are going to learn about the getKeys() method of ResourceBundle Class with its syntax and example.
Submitted by Preeti Jain, on March 24, 2020

ResourceBundle Class getKeys() method

  • getKeys() method is available in java.util package.
  • getKeys() method is used to get an enumeration of all the keys that exists in this ResourceBundle or its parent bundles.
  • getKeys() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • getKeys() method does not throw an exception at the time of returning the key set.

Syntax:

    public abstract Enumeration getKeys();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is Enumeration, it returns this ResourceBundle and its parent bundle keys in the form an Enumeration.

Example:

// Java program to demonstrate the example 
// of abstract Enumeration getKeys() method 
// of ResourceBundle

import java.util.*;

public class GetKeysOfResourceBundle {
 public static void main(String[] args) {
  // Instantiates ResourceBundle with
  // some locale
  ResourceBundle rb = ResourceBundle.getBundle("IncludeHelp...", Locale.FRANCE);

  System.out.println("rb.getKeys(): ");
  for (Enumeration en = rb.getKeys(); en.hasMoreElements();)
   System.out.println(en.nextElement());
 }
}

Output

rb.getKeys():
10
20
30
40


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.