Reputation: 7
I have a code in getting the value of a map named PUJ.
Map<String, Object> map = document.getData();
for (Map.Entry<String, Object> entry : map.entrySet()) {
if (entry.getKey().equals("PUJ")) {
Log.i(TAG, entry.getValue().toString());
}
}
Is it possible to get only the values: ABC123, YAG916?
Upvotes: 0
Views: 72
Reputation: 170
Map<String, Object> map = document.getData();
for (String key : map.keySet()) {
if ("PUJ".equals(key) && map.get(key) instanceof Map) {
Map<String, Object> pujMap = (Map<String, Object>) map.get(key);
//
}
}
Upvotes: 0
Reputation: 317497
The nested maps are also Map<String, Object>
, just like the document data. You can cast it if you want to assume the type:
Map<String, Object> map = document.getData();
Map<String, Object> puj = (Map<String, Object>) map.get("PUJ");
Set<String> keys = puj.keysSet();
// keys is now a Set that contains both "ABC123" and "YAG916"
But you should also check it with instanceof
to be sure.
Upvotes: 1