I’m looking forward to using the "google-api-translate-java" library.
In which there is a Language class. It’s an enum allowing to provide the language name and to get it’s value for Google Translate.
I can easily get all the values with :
for (Language l : values()) {
// Here I loop on one value
}
But what I’d want to get is a list of all the keys names (FRENCH, ENGLISH, …).
Is there something like a "keys()" method that’d allow me to loop through all the enum’s keys ?
An alternative to
Language.values()is to useEnumSet:This is useful if you want to use it in an API which uses the collections interfaces instead of an array. (It also avoids creating the array to start with… but needs to perform other work instead, of course. It’s all about trade-offs.)
In this particular case,
values()is probably more appropriate – but it’s worth at least knowing aboutEnumSet.EDIT: Judging by another comment, you have a concern about
toString()being overridden – callname()instead: