Home > Java > javaTutorial > body text

Usage and examples of valueOf method in Java

WBOY
Release: 2023-04-24 14:13:07
forward
1529 people have browsed it

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);
        }
 
}
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template