Friday, September 5, 2025
HomeLanguagesJavaLocale.Category valueOf() method in Java with Examples

Locale.Category valueOf() method in Java with Examples

The valueOf() method of java.util.Locale.Category enum in Java is used to get the value of the specified constant of this Locale.Category enum type. This method takes the constant name as the parameter.

Syntax:

public static Locale.Category valueOf(String name)

Parameter: This method accepts a parameter name which is the constant name whose value is to be retrieved from the Locale.Category enum.

Return Type: This method returns an instance of this Locale.Category enum type with the value of the specified name.

Exception: This method do not throw any exception.

Program 1:




// Java program to demonstrate
// the above method
  
import java.util.*;
import java.util.Locale.*;
  
public class LocaleCategoryDemo {
    public static void main(String[] args)
    {
  
        String name = "DISPLAY";
  
        // Getting the constant
        // of Locale.Category
        System.out.println("Locale.Category "
                           + "value of "
                           + name + ": "
                           + Locale.Category
                                 .valueOf(name));
    }
}


Output:

Locale.Category value of DISPLAY: DISPLAY

Program 2:




// Java program to demonstrate
// the above method
  
import java.util.*;
import java.util.Locale.*;
  
public class LocaleCategoryDemo {
    public static void main(String[] args)
    {
  
        String name = "FORMAT";
  
        // Getting the constant
        // of Locale.Category
        System.out.println("Locale.Category "
                           + "value of "
                           + name + ": "
                           + Locale.Category
                                 .valueOf(name));
    }
}


Output:

Locale.Category value of FORMAT: FORMAT

Reference: https://docs.oracle.com/javase/9/docs/api/java/util/Locale.Category.html#valueOf-java.lang.String-

RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6634 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11863 POSTS0 COMMENTS
Shaida Kate Naidoo
6750 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6701 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS