Ionică Bizău
Ionică Bizău

Reputation: 113355

Getting the languages from Language class

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: enter image description here

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

Answers (2)

Peter Lawrey
Peter Lawrey

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

dty
dty

Reputation: 18998

Since Language isn't an enum in that library, you'll have to use reflection to find all the members.

Upvotes: 2

Related Questions