Answers for "java enum from string"

1

java string enum

package test;

/**
 * @author The Elite Gentleman
 *
 */
public enum Strings {
    STRING_ONE("ONE"),
    STRING_TWO("TWO")
    ;

    private final String text;

    /**
     * @param text
     */
    Strings(final String text) {
        this.text = text;
    }

    /* (non-Javadoc)
     * @see java.lang.Enum#toString()
     */
    @Override
    public String toString() {
        return text;
    }
}
Posted by: Guest on March-29-2021
1

string to enum java

EnumType.valueOf(yourString)
Posted by: Guest on June-01-2021
1

java get enum from string

public enum Hello {
  A, B, C
};

val = Hello.valueOf("A") // Case sensitive and cannot have spaces in the string
val.equals(Hello.A) // returns true
Posted by: Guest on May-18-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language