Home > Blockchain >  How to find the corresponding Enum constructor value of a given value in Kotlin?
How to find the corresponding Enum constructor value of a given value in Kotlin?

Time:09-27

Below given is my enum class

enum class Letters(val display:String){
a("A"),
b("B"),
c("C")
}

Suppose I am getting the value 'a' as a result from an external function. How can I map it with the above enum to get the display value as "A" ?

Please help.

CodePudding user response:

val extResult = "a"
val letter = Letters.values().find { it.display.equals(extResult, ignoreCase = true) }

CodePudding user response:

fun main(){
   Letters.values{println(a)}
}

I think it will work

  • Related