Java.util.ListResourceBundle.handleGetObject() Method

Advertisements


Description

The java.util.ListResourceBundle.handleGetObject(String key) method gets an object for the given key from this resource bundle. Returns null if this resource bundle does not contain an object for the given key.

Declaration

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

public final Object handleGetObject(String key)

Parameters

  • key -- the key for the desired object

Return Value

This method returns the object for the given key, or null

Exception

  • NA

Example

The following example shows the usage of java.util.ListResourceBundle.handleGetObject() 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 object for key hello
      System.out.println("" + mr.handleGetObject("hello"));
   }
}

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

Hello World!



Advertisements
Advertisements