+ Start a Discussion
mahesh9999mahesh9999 

Can any one tell me how to use Map<string,string> ? using this i want get values and keys?

Raj VakatiRaj Vakati
1 . Initialize the Map
 
// Initialize the Map
Map<string, string> ProductCodeToProductName = new Map<string, string>
{'1000'=>'HCL', '1001'=>'H2SO4'};

// This statement would give as output as key value pair in Debug log
System.debug('value of ProductCodeToProductName'+ProductCodeToProductName);
2 .Get Key Set
 
// Return a set that contains all of the keys in the map
Set<String> SetOfKeys = ProductCodeToProductName.keySet();
System.debug('Value of Set with Keys '+SetOfKeys);
3. get Values
 
// Return a set that contains all of the keys in the map
List<String> values= ProductCodeToProductName.values();
System.debug('Value of Set with values'+values);

4.Retrieves a value
 
// Retrieves a value, given a particular key
String value = ProductCodeToProductName.get('1002');
System.debug('Value at the Specified key using get function: '+value);


 
NagendraNagendra (Salesforce Developers) 
Hi Mahesh,

May I suggest you please refer to the below article from the developer guide which has multiple map collection methods which uses string as key and string as value with different return types. Hope this helps.

Kindly mark this as solved if the reply was helpful.

Thanks,
Nagendra