Enum name() in Java

name(): This method is available in java.lang.Enum class of Java.

Syntax:

String java.lang.Enum.name()

This method returns the name of this enum constant, exactly as declared in its enum declaration.

Parameters: NA

Returns: the name of this enum constant.

Exceptions: NA

Approach

Java

enum Colour {
    RED, GREEN, GRAY, ORANGE
}

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

        System.out.println(Colour.RED.name());
    }
}

Output:

RED


No comments:

Post a Comment