[SalesForce] unable to fetch all Keys and Values in map

i am unable to fetch all Keys and Value simultaneously using forEach loop..

 for (Map<String,String> key : parameters) {

        queryParameters = key.values();//?
    }

Best Answer

If you want to fetch them all simultaneously, you have to do it outside the loop:

Map<String,String> aMap = new Map<String,String>();
Set<String> mapKeys = aMap.keySet();
List<String> mapValues = aMap.values();

Source: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_map.htm

If you absolutely need to all the keys inside a for loop (I don't know why... it sounds like bad practice to reference keys other than the one you're currently iterating), you can reference the mapKeys variable inside the for loop.

Or, just iterate and reference them one at a time as @MSCB described above