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!