Java Program to Convert Enum to String Last Updated : 17 Jun, 2021 Comments Improve Suggest changes 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 Enum to String 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 OutputStream to String OutputStream is an abstract class that is available in the java.io package. As it is an abstract class in order to use its functionality we can use its subclasses. Some subclasses are FileOutputStream, ByteArrayOutputStream, ObjectOutputStream etc. And a String is nothing but a sequence of character 2 min read Java Program to Convert Char to Int Given a char value, and our task is to convert it into an int value in Java. We can convert a Character to its equivalent Integer in different ways, which are covered in this article.Examples of Conversion from Char to Int:Input : ch = '3'Output : 3Input : ch = '9'Output : 9The char data type is a s 4 min read Convert String to Stream of Chars in Java The StringReader class from the java.io package in Java can be used to convert a String to a character stream. When you need to read characters from a string as though it were an input stream, the StringReader class can be helpful in creating a character stream from a string. In this article, we wil 2 min read How to Convert Char to String in Java? In this article, we will learn how to Convert Char to String in Java. If we have a char value like 'G' and we want to convert it into an equivalent String like "G" then we can do this by using any of the following three listed methods in Java. Using toString() method of Character classUsing valueOf( 5 min read How to Convert a String to a UUID in Java? A Universally Unique Identifier (UUID) is a 128-bit label utilised for information in computer systems. The term Globally Unique Identifier (GUID) is also used especially in Microsoft systems. UUIDs are regularised by the Open Software Foundation (OSF) as part of the Distributed Computing Environmen 2 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 Convert a String to a ByteBuffer in Java In Java, ByteBuffer can be used to perform operations at the Byte level one more thing is this class provides different types of methods for reading writing, and manipulating bytes in a structured way only. In this article, we will learn about String to ByteBuffer in Java. Java Program to Convert St 4 min read Like