You need to sign in to do that
Don't have an account?
chaitanyakuamar Teru
apex list debug result error
correct these code am not getting proper result....
list 1 am adding another value like already existing value bt am getting wrong result.
list<string>fcl= new list<string>();
fcl.add('red');
fcl.add('blue');
fcl.add('yellow');
fcl.add('orange');
fcl.add('blue');
system.debug('fcl'+fcl);
list<string>scl= new list<string>{'blue','black','yellow','green','blue'};
system.debug('scl'+scl);
map<string,integer>cc= new map<string,integer>();
for(string s1:fcl){
for(string s2:scl){
if(s1==s2){
if(cc.containskey(s1)){
cc.put(s1,cc.get(s1)+1);
}
else{
cc.put(s1,2);
}
}
}
}
system.debug('cc v'+cc);
list 1 am adding another value like already existing value bt am getting wrong result.
list<string>fcl= new list<string>();
fcl.add('red');
fcl.add('blue');
fcl.add('yellow');
fcl.add('orange');
fcl.add('blue');
system.debug('fcl'+fcl);
list<string>scl= new list<string>{'blue','black','yellow','green','blue'};
system.debug('scl'+scl);
map<string,integer>cc= new map<string,integer>();
for(string s1:fcl){
for(string s2:scl){
if(s1==s2){
if(cc.containskey(s1)){
cc.put(s1,cc.get(s1)+1);
}
else{
cc.put(s1,2);
}
}
}
}
system.debug('cc v'+cc);
hi chaitanyakuamar,
I did review your code in my org. it's working fine. I think you are getting some confuison.
I don't know what is your requirment but according this code it's working fine.
Please give me more details about your requirment And Tell me what the result you expect.
i have 2 list's
list1- {'red','blue','yellow','orange','blue'};
list2- {'blue','black','yellow','green','blue'}
with these list's am going to print common elements along with count like ANS:(blue=4,yellow=2);
by using above code. bt am getting output will be (blue=5,yellow=2) am getting extra blue element
that is my problem...
Hi chaitanyakuamar,
try following code. I think it will work as your expected.
Mark it as solved if it's help.
Thank Youbt still am getting an error I above code(yours) am already mention you that output will be (blue-4,yellow-2);
while am execute yours code output will be (blue-4,yellow-1).
it's wrong output