Kotlin Program to Lookup enum by the String value. we ‘ll deep dive into Kotlin enums.
With the evolution of programming languages, the usage and application of enums have also advanced.
Kotlin Program to Lookup Enum by String value
Source Code
enum class TextStyle {
BOLD, ITALICS, UNDERLINE, STRIKETHROUGH
}
fun main(args: Array<String>) {
val style = "Bold"
val textStyle = TextStyle.valueOf(style.toUpperCase())
println(textStyle)
}
Output
Kotlin Program to Lookup Enum by String value