// 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);
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.
2 .Get Key Set
3. get Values
4.Retrieves a value
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.
- https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_map.htm
- https://micropyramid.com/blog/how-to-use-map-methods-in-salesforce/
Hope this helps.Kindly mark this as solved if the reply was helpful.
Thanks,
Nagendra