You need to sign in to do that
Don't have an account?
Rahul Mahale
need to print Key & Values line by line
I need to print in O/P of Stored values in Keys & Associated values line by line of Map function.
o/p required :
the current key =98
the current value for above key = Robert
What enhancement should i do to achieve o/p?
Code :
//Declare Map Variable & Show key Values, Values & Check if it is empty or not.
Map<integer, String> VarMapOfEmployeeMobileNum= New Map <integer, String>();
//add some items
VarMapOfEmployeeMobileNum.put(98,'Robert');
VarMapOfEmployeeMobileNum.put(64,'Matthew');
VarMapOfEmployeeMobileNum.put(55,'Harry');
//to see the map
System.debug('The current map ='+VarMapOfEmployeeMobileNum);
//Collect all Keys and Show 1 By 1
set<Integer> VarTempSet = new set<Integer>();
VarTempSet = VarMapOfEmployeeMobileNum.keyset();
for (integer VarMobileSetPrint: VarTempSet)
{
system.debug('The Current Key ='+VarMobileSetPrint);
}
//Collect all Values and Show 1 By 1
List<String> VarTempList = new List<String>();
VarTempList = VarMapOfEmployeeMobileNum.Values();
for (string VarMobileListPrint: VarTempList)
{
system.debug('The Current Value for above Key ='+VarMobileListPrint);
}
o/p required :
the current key =98
the current value for above key = Robert
What enhancement should i do to achieve o/p?
Code :
//Declare Map Variable & Show key Values, Values & Check if it is empty or not.
Map<integer, String> VarMapOfEmployeeMobileNum= New Map <integer, String>();
//add some items
VarMapOfEmployeeMobileNum.put(98,'Robert');
VarMapOfEmployeeMobileNum.put(64,'Matthew');
VarMapOfEmployeeMobileNum.put(55,'Harry');
//to see the map
System.debug('The current map ='+VarMapOfEmployeeMobileNum);
//Collect all Keys and Show 1 By 1
set<Integer> VarTempSet = new set<Integer>();
VarTempSet = VarMapOfEmployeeMobileNum.keyset();
for (integer VarMobileSetPrint: VarTempSet)
{
system.debug('The Current Key ='+VarMobileSetPrint);
}
//Collect all Values and Show 1 By 1
List<String> VarTempList = new List<String>();
VarTempList = VarMapOfEmployeeMobileNum.Values();
for (string VarMobileListPrint: VarTempList)
{
system.debug('The Current Value for above Key ='+VarMobileListPrint);
}
try following code.
get value based key.
I hope above info will help you and if it help, let me know to mark it as best answer.
Thank you
All Answers
Please replace your code with below code:-
Please mark it as Best Answer if it helps you.
Thanks & Regards
Suraj Tripathi
try following code.
get value based key.
I hope above info will help you and if it help, let me know to mark it as best answer.
Thank you