Write a Java Program to Lookup enum by String value

Java Program to Lookup enum by String value

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn Java programming concepts. You can learn Java  language at your own speed and time. One can learn concepts of Java language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Java Program to Lookup enum by String value
Java Program to Lookup enum by String value

Write a Java Program to Lookup enum by String value

PROGRAM: Java Program to Lookup enum by String value

/*Java Program to Lookup enum by String value*/

public class EnumString {

public enum TextStyle {
BOLD, ITALICS, UNDERLINE, STRIKETHROUGH
}

public static void main(String[] args) {

String style = “Bold”;

TextStyle textStyle = TextStyle.valueOf(style.toUpperCase());

System.out.println(textStyle);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *