Enum: get a list of keys

I am not a Java developer. But I'm looking at Android app development right now, so I'm doing a bit of nostalgia, doing a few java again without touching it for three years.

I look forward to using google-api-translate-java library.
Which has a Language class . This listing allows you to provide the name of the language and get its meaning for Google Translate.

I can easily get all the values ​​with:

for (Language l : values()) {
    // Here I loop on one value
}

But I would like to get a list of all the key names (FRENCH, ENGLISH, ...).
Is there something like the "keys ()" method that would allow me to iterate over all the enumeration keys?

+3
source share
3

Language.values() EnumSet:

for (Language l : EnumSet.allOf(Language.class))
{
}

, API, . ( , ... , , . .)

values(), , - , , EnumSet.

: , , toString() - name() :

for (Language l : Language.values())
{
    String name = l.name();
    // Do stuff here
}
+10

. X, X.values ​​(). . .

+1

Source: https://habr.com/ru/post/1742768/


All Articles