Charset displayName() locale in Java

displayName(): This method is available in java.nio.charset.Charset class of Java.

Syntax:

String java.nio.charset.Charset.displayName(Locale locale)

This method takes one argument of type Locale as its parameter. This method returns this charset's human-readable name for the given locale. The default implementation of this method simply returns this charset's canonical name.

Parameters: One parameter is required for this method.

locale: The locale for which the display name is to be retrieved.

Returns: The display name of this charset in the given locale.

For Exmaple:

Charset cs = Charset.forName("UTF-8")

Locale locale = new Locale("en", "US")

cs.displayName(locale) = > It returns UTF-8

Approach

Java

import java.nio.charset.Charset;
import java.util.Locale;

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

        Charset cs = Charset.forName("UTF-8");

        Locale locale = new Locale("en""US");
        System.out.println(cs.displayName(locale));
    }
}

Output:

UTF-8

No comments:

Post a Comment