ResourceBundle.Control getFormats(String) in Java

getFormats(String): This method is available in java.util.ResourceBundle.Control class of Java.

Syntax:

List<String> java.util.ResourceBundle.Control.getFormats(String baseName)

This method takes one argument. This method returns a List of Strings containing formats to be used to load resource bundles for the given baseName.

Parameters: One parameter is required for this method.

baseName: the base name of the resource bundle, a fully qualified classname.

Returns: a List of Strings containing formats for loading resource bundles.

Throws:

NullPointerException - if baseName is null

Approach 1: When no exception

Java

import java.util.ResourceBundle;
import java.util.ResourceBundle.Control;

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

        ResourceBundle.Control reControl =
ResourceBundle.Control.getControl(Control.FORMAT_DEFAULT);

        String baseName = "Hello";
        System.out.println(reControl.getFormats(baseName));
    }
}

Output:

[java.class, java.properties]


Approach 2: NullPointerException

Java

import java.util.ResourceBundle;
import java.util.ResourceBundle.Control;

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

        ResourceBundle.Control reControl =
ResourceBundle.Control.getControl(Control.FORMAT_DEFAULT);

        String baseName = null;
        System.out.println(reControl.getFormats(baseName));
    }
}

Output:

Exception in thread "main" java.lang.NullPointerException at java.base/java.util.ResourceBundle$Control.getFormats(ResourceBundle.java:2690)


No comments:

Post a Comment