Home » Java programming language

Java ResourceBundle getString() Method with Example

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

ResourceBundle Class getString() method

  • getString() method is available in java.util package.
  • getString() method is used to get a string for the given key element (key_ele) from this ResourceBundle or any one of its parent class.
  • getString() 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.
  • getString() method may throw an exception at the time of getting a string.
    • NullPointerException: This exception may throw when the given parameter is null exists.
    • MissingResourceException: This exception may throw when no object exists for the given key element (key_ele).

Syntax:

    public final String getString(String key_ele);

Parameter(s):

  • String key_ele – represents the key element whose desired string is to be retrieved.

Return value:

The return type of this method is String, it returns desired string object for the given parameter of this ResourceBundle when exists.

Example:

// Java program to demonstrate the example 
// of String getString(String key_ele) method 
// of ResourceBundle

import java.util.*;

public class GetStringOfResourceBundle {
 public static void main(String[] args) {
  // Instantiates ResourceBundle with
  // some locale
  ResourceBundle rb = ResourceBundle.getBundle("IncludeHelp...", Locale.JAPAN);

  // By using getString() method is
  // to get the string defined for the
  // given key from this rb or in its parent
  System.out.println("rb.getString(IncludeHelp...): " + rb.getString("IncludeHelp..."));
 }
}

Output

rb.getString(IncludeHelp...): Website


Comments and Discussions!

Load comments ↻





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