A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/java/util/java_util_resourcebundle.htm below:

Java ResourceBundle Class

Java ResourceBundle Class Introduction

The Java ResourceBundle class contain locale-specific objects.Following are the important points about ResourceBundle −

Class declaration

Following is the declaration for java.util.ResourceBundle class −

public abstract class ResourceBundle
   extends Object
Field

Following are the fields for java.util.ResourceBundle class −

protected ResourceBundle parent − This is the parent bundle of this bundle.

Class constructors Sr.No. Constructor & Description 1

ResourceBundle()

This is the single constructor.

Class methods Methods inherited

This class inherits methods from the following classes −

Getting Keys of a ResourceBundle Example

The following example shows the usage of Java ResourceBundle getKeys() method to print list of keys present in the properties file. We've created a resource bundle of US Locale for the corresponding hello_en_US.properties file. Then we printed the text assigned to key hello. Then the enumeration of keys is retrieved using getKeys() method and keys are printed.

package com.tutorialspoint;

import java.util.Enumeration;
import java.util.Locale;
import java.util.ResourceBundle;

public class ResourceBundleDemo {
   public static void main(String[] args) {

      // create a new ResourceBundle with specified locale
      ResourceBundle bundle = ResourceBundle.getBundle("hello", Locale.US);

      // print the text assigned to key "hello"
      System.out.println("" + bundle.getString("hello"));

      // get the keys
      Enumeration<String> enumeration = bundle.getKeys();

      // print all the keys
      while (enumeration.hasMoreElements()) {
         System.out.println("" + enumeration.nextElement());
      }
   }
}
Output

Assuming we have a resource file hello_en_US.properties available in your CLASSPATH, with the following content. This file will be used as an input for our example program −

hello = Hello World!
bye = Goodbye World!
morning = Good Morning World!

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4