Skip to content
Advertisement

How to use enum key value in java

I want to create an enum class in java 11 with key value I create a enum like this

JavaScript

the problem that when i do Saison saison.getvalues() i got like this

JavaScript

But i want to got like this

JavaScript

how can i call my enum tio get a result like this

Advertisement

Answer

There is nothing to prevent you from returning a map entry which contains the key,value pair.

JavaScript

or print the toString() value of the Entry.

JavaScript

Prints

JavaScript

You can also override toString of your Enum and do something like this.

JavaScript

Prints

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement