Reputation: 113355
I use this Unofficial Java Google Translate API to translate a text from a language to another language.
I have Language
class that contains the all language names like in the image bellow:
I want to get an array with the languages names. How can I do this?
If it would be C# I would do this:
PropertyInfo[] languages;
languages = typeof(Language).GetProperties();
Upvotes: 1
Views: 98
Reputation: 533492
You can get all the fields with
Field[] fields = Language.class.getDeclaredFields();
for(Field field: fields)
if (field.getType() == String.class)
System.out.println(field.getName() + " = " + field.get(null));
Upvotes: 1
Reputation: 18998
Since Language
isn't an enum
in that library, you'll have to use reflection to find all the members.
Upvotes: 2