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
Manoprabha PalpandianManoprabha Palpandian 

if i select the district key display the particular district pincode how to write the code using map method

Best Answer chosen by Manoprabha Palpandian
Suraj Tripathi 47Suraj Tripathi 47
Public class NewRegistrationController{

Public static void data(){

map<String,Integer> mapName=new map<String,Integer>(); 
mapName.put('Delhi',110003); 
mapName.put('South Delhi',110004); 
mapName.put('West Delhi',110005);
 mapName.put('Old Delhi',110006); 
mapName.put('New Delhi',110007);
 for(String str:mapName.KeySet()){ 
System.debug('Pin code = '+mapName.get(str));
 }

 System.debug('Pin code of Delhi is= '+mapName.get('Delhi'));

}

}

To execute this class : ctrl+E then put NewRegistrationController.data();

User-added image

Click on execute

Please mark it as the Best Answer

Thank You

All Answers

Suraj Tripathi 47Suraj Tripathi 47

Hi,

Please find the solution.

map<String,Integer> mapName=new map<String,Integer>();

mapName.put('Delhi',110003);
mapName.put('South Delhi',110004);
mapName.put('West Delhi',110005);
mapName.put('Old Delhi',110006);
mapName.put('New Delhi',110007);


for(String str:mapName.KeySet()){
  System.debug('Pin code = '+mapName.get(str));
}

or
System.debug('Pin code of Delhi is= '+mapName.get('Delhi'));

Please mark it as the Best Answer if it helps you

Thank You

Manoprabha PalpandianManoprabha Palpandian
using this code how to get the output in my customcontroller can you helpme
Manoprabha PalpandianManoprabha Palpandian
public class NewRegistrationController
{
    public Registration__c reg {get;set;}
}
Suraj Tripathi 47Suraj Tripathi 47
Public class NewRegistrationController{

Public static void data(){

map<String,Integer> mapName=new map<String,Integer>(); 
mapName.put('Delhi',110003); 
mapName.put('South Delhi',110004); 
mapName.put('West Delhi',110005);
 mapName.put('Old Delhi',110006); 
mapName.put('New Delhi',110007);
 for(String str:mapName.KeySet()){ 
System.debug('Pin code = '+mapName.get(str));
 }

 System.debug('Pin code of Delhi is= '+mapName.get('Delhi'));

}

}

To execute this class : ctrl+E then put NewRegistrationController.data();

User-added image

Click on execute

Please mark it as the Best Answer

Thank You

This was selected as the best answer
Manoprabha PalpandianManoprabha Palpandian
thank you