Home  >  Article  >  Java  >  Usage and examples of valueOf method in Java

Usage and examples of valueOf method in Java

WBOY
WBOYforward
2023-04-24 14:13:071532browse

1. Concept

Get a single enumeration object through a string. There are three syntax forms.

2. Parameter

i, the integer of the Integer object.

s, string of Integer object.

radix, the base number used when parsing the string s, used to specify the base number used.

3. Return value

An integer object represented by a string parameter

Exception. If the string cannot be parsed, a NumberFormatException exception is thrown.

4. Example

public enum Signal {
 
        //定义一个枚举类型
        GREEN,YELLOW,RED;
 
        public static void main(String[] args)
        {
            Signal green = Signal.valueOf("GREEN");
            System.out.println(green);
        }
 
}

The above is the detailed content of Usage and examples of valueOf method in Java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete