I need to get HashMap which is already inside of HashMap as a value.
HashMap<String, HashMap<String, Product>> myOrders = new HashMap<>();
myOrders = firebaseMethods.getOrders(FirebaseAuth.getInstance().getCurrentUser().getUid(),snapshot);
List<String> Keys = new ArrayList<>(myOrders.keySet());
HashMap<String,Product> Values = myOrders.values();
I’ve tried already .values() method but it didn’t work, any ideas how I can achieve this.
>Solution :
Calling .values() will return a collection of ‘values’ (in your case, a collection of HashMaps). You can use something like:
List<String> keys = new ArrayList<>(myOrders.keySet());
for(String key: keys) {
HashMap<String, Product> productMap = myOrders.get(key); // This will return the HashMap for the 'key'
... // processing logic goes here
Or better still (as suggested in the comments):
for(Entry<String, Map<String, Product>> entry: map.entrySet()) {
Map<String, Product> productMap = entry.getValue();
// processing logic here ...