Home » Java programming language

Java ListResourceBundle getKeys() Method with Example

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

ListResourceBundle Class getContents() method

  • getContents() method is available in java.util package.
  • getContents() method is used to return an enumeration of all the keys that exist in this ListResourceBundle and its superclass.
  • getContents() 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.
  • getContents() method does not throw an exception at the time of returning an enumeration of elements.

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 all the existing keys in this ListResourceBundle and its super bundle.

Example:

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

import java.util.*;

// Instantiates a class that extends
// ListResourceBundle 
class GetKey extends ListResourceBundle {
 // By using getContent() method is to
 // get the contents in the form of 
 // 2D objects

 protected Object[][] getContents() {
  return new Object[][] {
   {
    "10",
    "C"
   }, {
    "20",
    "C++"
   }, {
    "30",
    "JAVA"
   }, {
    "40",
    "SFDC"
   }, {
    "50",
    "PHP"
   }
  };
 }
}

public class Main {
 public static void main(String[] args) {
  // Instantiates an object of
  // GetKeys
  GetKey get_c = new GetKey();

  // By using getKeys() method is 
  // return all the keys in the 
  // form of an Enumeration

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

Output

get_c.getKeys(): 
50
40
30
20
10


Comments and Discussions!

Load comments ↻





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