You need to sign in to do that
Don't have an account?
Rahul Chavan 36
loop
hey guys as beginner in apex my reqmt to write ver basic apex code with for loop not which use in apex like chaeck condition directly with sign :
so for map i want to print map1 key is one and value is first element
map1 key is two and value is 2nd element and it goes on..
i tried to build logic but it will not work , below is my logic code
map<string,string> mapr = new map<string,string>();
mapr.put('one','first element');
mapr.put('two','2nd element');
mapr.put('three','3rd element');
system.debug('mapr= ' +mapr);
integer maprsize = mapr.size();
set <string> maprkeys=mapr.keyset();
list<string> maprvalues= mapr.values();
****for (string x<= maprkeys; x++){
system.debug('for mapr key is ' + maprkeys + ' and its value is ' + maprvalues );
system.debug(x);
}
and signed star portion is error , so kindly help to get map keys and then by that keys we print values .by standard for loop , not the one for loop which we use in apex ,below also i give the apex code for loop which work but i want to also work in standard for
map<string,string> map1= new map<string,string>;
map1.put('one', 'first element');
map 1.put('two','2nd element');
system.debug('map= ' +map1);
for(string mapitem : map1.keyset() {
string tempstring = 'key is ' +map1item+ ' , and its value is ' +map1.get(map1item);
system.debug(tempstring);
}
as a beginner i know its basic but plz help me out with same simple code..
so for map i want to print map1 key is one and value is first element
map1 key is two and value is 2nd element and it goes on..
i tried to build logic but it will not work , below is my logic code
map<string,string> mapr = new map<string,string>();
mapr.put('one','first element');
mapr.put('two','2nd element');
mapr.put('three','3rd element');
system.debug('mapr= ' +mapr);
integer maprsize = mapr.size();
set <string> maprkeys=mapr.keyset();
list<string> maprvalues= mapr.values();
****for (string x<= maprkeys; x++){
system.debug('for mapr key is ' + maprkeys + ' and its value is ' + maprvalues );
system.debug(x);
}
and signed star portion is error , so kindly help to get map keys and then by that keys we print values .by standard for loop , not the one for loop which we use in apex ,below also i give the apex code for loop which work but i want to also work in standard for
map<string,string> map1= new map<string,string>;
map1.put('one', 'first element');
map 1.put('two','2nd element');
system.debug('map= ' +map1);
for(string mapitem : map1.keyset() {
string tempstring = 'key is ' +map1item+ ' , and its value is ' +map1.get(map1item);
system.debug(tempstring);
}
as a beginner i know its basic but plz help me out with same simple code..
take referance from below code. if it helps you, don't forget to mark it as best answer.
Thank you
Hi,
Please find the solution.
Thank Youbut as i mentioned i do not want it by apex for loop and by : method which you used(
for(string mapitem : map1.keyset()) but with sttandard for loop without : this sybmol it will return key and its value hope u answer it as well