Home » Java programming language

Java ListResourceBundle handleKeySet() Method with Example

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

ListResourceBundle Class handleKeySet() method

  • handleKeySet() method is available in java.util package.
  • handleKeySet() method is used to get a set of all the existing keys in this ListResourceBundle.
  • handleKeySet() 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.
  • handleKeySet() method does not throw an exception at the time of returning the key set.

Syntax:

    public Set handleKeySet();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of the method is Set, it returns Set view of all the existing keys in this ListResourceBundle.

Example:

// Java program to demonstrate the example 
// of Set handleKeySet()  method 
// of ListResourceBundle 

import java.util.*;

// Instantiates a class that extends
// ListResourceBundle 
class GetKeySet 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"
   }
  };
 }

 protected Set < String > handleKeySet() {
  return new LinkedHashSet < String > ();
 }
}

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

  // By using handleGetObject() method is
  // reurn the object for the given key
  // element 20 "C++"

  System.out.print("get_ob.getString(20): ");
  System.out.println(get_ob.getString("20"));
 }
}

Output

get_ob.getString(20): C++



Comments and Discussions!

Load comments ↻






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