You need to sign in to do that
Don't have an account?
Rahul Chavan 36
for loop
hey guys plz refer below code in which by using for loop and : this symbol we fetch maps key and value but i dont want to use it but with for loop how i acheive it.. as beginner plz help me out..
map<string,string> mapr = new map<string,string>();
// <key,value>
mapr.put('one','first element');
mapr.put('two','2nd element');
mapr.put('three','3rd element');
//iterate over keyset
for(string str:mapr.Keyset()){
system.debug('Key=> '+str+' Values=> '+mapr.get(str));
}
so without this(string str:mapr.Keyset()) method
how i acheived it in for loop to print maps key values and values??
map<string,string> mapr = new map<string,string>();
// <key,value>
mapr.put('one','first element');
mapr.put('two','2nd element');
mapr.put('three','3rd element');
//iterate over keyset
for(string str:mapr.Keyset()){
system.debug('Key=> '+str+' Values=> '+mapr.get(str));
}
so without this(string str:mapr.Keyset()) method
how i acheived it in for loop to print maps key values and values??
Above is the only way to iterate over collection variable.
Please check out the Apex help documentation around it:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_loops_for_lists.htm
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_loops_for.htm
Hope above information helps. Please mark as Best Answer so that it can help others in future.
Thanks.