Java Program to Convert Enum to String Last Updated : 17 Jun, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report Given an enum containing a group of constants, the task is to convert the enum to a String. Methods: We can solve this problem using two methods: Using name() MethodUsing toString() Method Let us discuss both of them in detail and implementing them to get a better understanding of the same. Method 1: Using name() Method It returns the name of the enum constant same as declared in its enum declaration. We would be using name() method to return the name of the enum constant.In the main class, we just have to print it.The value given inside is first the name of the enum class that we will create further, then calling the constant that is named, finally using the name() method.Now create another java enum file named Fruits.java in the same folder where you created the main file, and declare the enum as follows: Example public enum Fruits { Orange, Apple, Banana, Mango; } Java // Java Program to Convert Enum to String // using // Importing input output classes import java.io.*; // Enum enum Fruits { Orange, Apple, Banana, Mango; } // Main class class GFG { // Main driver method public static void main(String[] args) { // Printing all the values System.out.println(Fruits.Orange.name()); System.out.println(Fruits.Apple.name()); System.out.println(Fruits.Banana.name()); System.out.println(Fruits.Mango.name()); } } OutputOrange Apple Banana Mango Method 2: Using toString() Method It is used to get a string object which represents the value of the number object. We will be following the same procedure as earlier used but the only difference here is that we will be using toString() method. So just replace name() method with toString() method. Note: Do not forgot to create a Fruits.java enum file in the same folder. Illustration: public enum Fruits { Orange, Apple, Banana, Mango; } Example 2 Java // Java Program to Convert Enum to String // Using toString() Method // Importing input output classes import java.io.*; // Enum enum Fruits { // Custom entries Orange, Apple, Banana, Mango; } // Main class class Main { // Main driver method public static void main (String[] args) { // Printing all the values System.out.println(Fruits.Orange.toString()); System.out.println(Fruits.Apple.toString()); System.out.println(Fruits.Banana.toString()); System.out.println(Fruits.Mango.toString()); } } OutputOrange Apple Banana Mango Comment More infoAdvertise with us Next Article Java Program to Convert Boolean to String K kunalmali Follow Improve Article Tags : Java Java Programs Java-String-Programs Java-Enumeration Practice Tags : Java Similar Reads Java Program to Convert Long to String The long to String conversion in Java generally comes in need when we have to display a long number in a GUI application because everything is displayed in string form. In this article, we will learn about Java Programs to convert long to String. Given a Long number, the task is to convert it into a 4 min read Java Program to Convert String to Object In-built Object class is the parent class of all the classes i.e each class is internally a child class of the Object class. So we can directly assign a string to an object. Basically, there are two methods to convert String to Object. Below is the conversion of string to object using both of the me 2 min read Java Program to Convert Boolean to String In Java programming, you might come across the need to convert a simple "true" or "false" boolean value into a String. It may seem like a challenging task, but fear not! In this article, You will explore some methods to convert a boolean value to a string in Java Method for Boolean to String Convers 4 min read Java Program to Convert String to Byte Array Using getBytes() Method In Java, strings are objects that are backed internally by a char array. So to convert a string to a byte array, we need a getByte() method. It is the easiest way to convert a string to a byte array. This method converts the given string to a sequence of bytes using the platform's default charset an 2 min read Java Program to Access All the Constant Defined in the Enum An enum is a special class that represents a group of constants. To create an enum, use the enum keyword (instead of class or interface), and separate the constants with a comma. enum Day{ SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY; } values() method can be used to return all val 1 min read Java Program to Define Ordinal() Method Using Enum Concept Java enum, also called Java enumeration type, is a type whose fields consist of a fixed set of constants. The java.lang.Enum.ordinal() tells about the ordinal number(it is the position in its enum declaration, where the initial constant is assigned an ordinal of zero) for the particular enum. ordina 2 min read Like