img
Method
Description
Loads the resource bundle with a family name of
static ResourceBundle
getBundle(String familyName,
familyName using the specified locale and the specified
Locale loc,
class loader. The loading process is under the control of
ClassLoader ldr,
cntl. Throws MissingResourceException if no resource
ResourceBundle.Control cntl)
bundle matching the family name specified by familyName
is available. (Added by Java SE 6.)
abstract Enumeration<String> getKeys( )
Returns the resource bundle keys as an enumeration of
strings. Any parent's keys are also obtained.
Locale getLocale( )
Returns the locale suppor ted by the resource bundle.
final Object getObject(String k)
Returns the object associated with the key passed via k.
Throws MissingResourceException if k is not in the
resource bundle.
final String getString(String k)
Returns the string associated with the key passed via k.
Throws MissingResourceException if k is not in the
resource bundle. Throws ClassCastException if the
object associated with k is not a string.
final String[ ] getStringArray(String k)
Returns the string array associated with the key passed
via k. Throws MissingResourceException if k is not in the
resource bundle. Throws ClassCastException if the
object associated with k is not a string array.
Returns the object associated with the key passed via k.
protected abstract Object
handleGetObject(String k)
Returns null if k is not in the resource bundle.
protected Set<String> handleKeySet( )
Returns the resource bundle keys as a set of strings. No
parent's keys are obtained. Also, keys with null values
are not obtained. (Added by Java SE 6.)
Set<String> keySet( )
Returns the resource bundle keys as a set of strings. Any
parent keys are also obtained. (Added by Java SE 6.)
Sets parent as the parent bundle for the resource bundle.
protected void
setParent(ResourceBundle parent)
When a key is looked up, the parent will be searched if
the key is not found in the invoking resource object.
TABLE 18-17
The Methods Defined by ResourceBundle (continued)
its own. The second is the abstract class ListResourceBundle, which manages resources in
an array of key/value pairs. ListResourceBundle adds the method getContents( ), which
all subclasses must implement. It is shown here:
protected abstract Object[ ][ ] getContents( )
It returns a two-dimensional array that contains key/value pairs that represent resources.
The keys must be strings. The values are typically strings, but can be other types of objects.
Here is an example that demonstrates using a resource bundle. The resource bundle
has the family name SampleRB. Two resource bundle classes of this family are created by
extending ListResourceBundle. The first is called SampleRB, and it is the default bundle
(which uses English). It is shown here:
import java.util.*;
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home