function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DeepikareddyDeepikareddy 

Hi developers how to get the keyset(); and values() form loop using the Map class

map<string,string> custmap = new map<string,stirng>();(declared and initialised in the constructor)
 Example1:in Debug window the custmap values are :
 {Andrapradesh=5.0, Karnataka=3.0, Maharastra=2.5, Telangana=4.0}

//How to print the keyset and values :

 for(list<wrapper> s: custmap){
       system.debug(s.keyset());
        system.debug(s.Values());
     
      }

//wrapperclass 
public class wrapper{
public string statename;
public string rating;
}

Thanks
Deepika
Prafull G.Prafull G.
Keys and values can be any data type—primitive types, collections, sObjects, user-defined types, and built-in Apex types. You can iterate these and print/get key/values. Here is a snippet form documentations -
Map<Integer, String> m = new Map<Integer, String>(); // Define a new map
m.put(1, 'First entry');                  // Insert a new key-value pair in the map
m.put(2, 'Second entry');                  // Insert a new key-value pair in the map
System.assert(m.containsKey(1));  // Assert that the map contains a key
String value = m.get(2);               // Retrieve a value, given a particular key
System.assertEquals('Second entry', value);
Set<Integer> s = m.keySet();       // Return a set that contains all of the keys in the map