+ Start a Discussion

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){

public class wrapper{
public string statename;
public string rating;

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