How to convert java enum to string ?

Example

package com.pretech;
public class EnumToStringExample {
	public static void main(String[] args) {
		String days = Days.MONDAY.name();
		System.out.println(days + "    " + days.getClass());
	}
}
enum Days {
	MONDAY
}

Output



MONDAY    class java.lang.String


No comments:

Post a Comment

12 classic String-based Java interview questions with simple explanations and code.

  1️⃣ Check if a String is a Palindrome Problem Given a string, check if it reads the same forward and backward. Example: "madam...

Featured Posts