Using Enum values as String literals


Every enum has both a name() and a valueOf(String) method. The former returns the string name of the enum, and the latter gives the enum value whose name is the string. Is this like what you're looking for?

String name =;
Modes mode = Modes.valueOf(name);

There's also a static valueOf(Class, String) on Enum itself, so you could also use

Modes mode = Enum.valueOf(Modes.class, name);


What is the best way to use the values stored in an Enum as String literals? For example:

public enum Modes {

Then later I could use Mode.mode1 to return its string representation as mode1. Without having to keep calling Mode.model.toString().

Using Enum values as String literals

You can't. I think you have FOUR options here. All four offer a solution but with a slightly different approach...

Option One: use the built-in name() on an enum

    String name =; // Returns the name of this enum constant, exactly as declared in its enum declaration.

Option Two: add overriding properties to your enums if you want more control

public enum Modes {
    mode1 ("Fancy Mode 1"),
    mode2 ("Fancy Mode 2"),
    mode3 ("Fancy Mode 3");

    private final String name;       

    private Modes(String s) {
        name = s;

    public boolean equalsName(String otherName) {
        // (otherName == null) check is not needed because name.equals(null) returns false 
        return name.equals(otherName);

    public String toString() {

Option Three: use static finals instead of enums:

public final class Modes {

    public static final String MODE_1 = "Fancy Mode 1";
    public static final String MODE_2 = "Fancy Mode 2";
    public static final String MODE_3 = "Fancy Mode 3";

    private Modes() { }

Option Four: interfaces have every field public, static and final:

public interface Modes {

    String MODE_1 = "Fancy Mode 1";
    String MODE_2 = "Fancy Mode 2";
    String MODE_3 = "Fancy Mode 3";  

You could override the toString() method for each enum value.


public enum Country {

  DE {
    public String toString() {
      return "Germany";
  IT {
    public String toString() {
      return "Italy";
  US {
    public String toString() {
      return "United States";



public static void main(String[] args) {
  System.out.println(Country.DE); // Germany
  System.out.println(Country.IT); // Italy
  System.out.println(Country.US); // United States

if status is of type Status enum, will give you its defined name.

Java convert a string to list of enums

Your question doesn't really make much sense. If you want to send or store list of enums then you can simply serialize and deserialize it since ArrayList and each enum are Serializable.


List<Day> ofiginalList = new ArrayList<Day>();

ByteArrayOutputStream bout = new ByteArrayOutputStream();

ObjectOutput out = new ObjectOutputStream(bout);

ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
ObjectInput in = new ObjectInputStream(bin);

List<Day> deserializedList = (List<Day>) in.readObject();

Output: [Monday, Tuesday].

You can try doing something like

List<Day> days = new ArrayList<>();
StringTokenizer tokenizer = new StringTokenizer("[Monday, Tuesday]", "[], ");
while (st.hasMoreTokens()) {
  String token = st.nextToken();
  days.add(Day.valueOf(Day.class, token));