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

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.