Skip to content
Advertisement

Java Get Value from Object by Key Name

I have retrieved an object from Firebase and would like to access the values of it using the name of each field I would like the value for. In javascript, this would be something as simple as myObject.name to retrieve the name in the object.

How can I do the equivalent in Java?

JavaScript

Advertisement

Answer

Try this:

JavaScript

If you have a properly defined User class, than this would work even better:

JavaScript

Finally, there is a third option as well (using DataSnapshot.child(String) method):

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