Home » Java programming language

Java PropertyResourceBundle getKeys() Method with Example

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

PropertyResourceBundle Class getKeys() method

  • getKeys() method is available in java.util package.
  • getKeys() method is used to return an enumeration of the keys that exist in this PropertyResourceBundle and its parent.
  • 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 Enumeration getKeys();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of the method is Enumeration, it gets an enumeration of the existing keys of this PropertyResourceBundle and its super class.

Example:

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

import java.io.*;
import java.util.*;

public class GetKeyOfPropertyResourceBundle {
 public static void main(String arg[]) throws Exception {
  // Instantiate Properties object
  String str = "10 = C\n" + " 20 =C++\n " + " 30 =Java\n ";
  InputStream is = new StringBufferInputStream(str);

  PropertyResourceBundle prb = new PropertyResourceBundle(is);
  Enumeration en = prb.getKeys();

  for (; en.hasMoreElements();)
   System.out.println(en.nextElement());
 }
}

Output

30
20
10


Comments and Discussions!

Load comments ↻





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