You need to sign in to do that
Don't have an account?
PS81
two Dimensional list - string
Hi
i have a two dimensinal array populated but need help on how to iterate thru it:
List<List<string>> Wdays = new List<list<string>>();
List<String> Mnth = new List<String>();
Mnth.add('JAN'); Mnth.add(string.valueof(jan));
Wdays.add(mnth);
I wish to know how to loop thru the two dimensional list to display the values...any help please?
i have a two dimensinal array populated but need help on how to iterate thru it:
List<List<string>> Wdays = new List<list<string>>();
List<String> Mnth = new List<String>();
Mnth.add('JAN'); Mnth.add(string.valueof(jan));
Wdays.add(mnth);
I wish to know how to loop thru the two dimensional list to display the values...any help please?
You can then obtain the value for each month in this way:
All Answers
Wdays.add(new List<String>{'Monday', 'Tuesday', 'Wednesday'});
Wdays.add(new List<String>{'Thrusday', 'Friday', 'Saturday'});
Wdays.add(new List<String>{'Sunday'});
//this is how you iterate through two dimensional array.
for(Integer i=0;i < Wdays.size();i++)
for(Integer j=0;j < Wdays[i].size();j++)
{
String val = Wdays[i][j];
System.debug(val);
}
Does this help?
The two FOR loops is what you are looking for I believe. The first 4 lines are just added for context and for testing pupose.
i'm not sure if i'm using the array of list in the right way.....all i wanted is
wdays ={(Jan,31),(feb,28)....)
with the below code i think i'm not getting what i need:
mnth.add('JAN'); Mnth.add(string.valueof(jan)); Wdays.add(mnth);
mnth.add('FEB'); Mnth.add(string.valueof(feb)); Wdays.add(mnth);
mnth.add('MAR'); Mnth.add(string.valueof(mar)); Wdays.add(mnth);
You are always adding the reference to the same object when you call "Wdays.add(mnth);" so you end up with one object being added 3 times to Wdays array and it has values for 'JAN', 'FEB' and 'MAR' added to it.
You can then obtain the value for each month in this way:
Wdays.add(new List<string>{'Jan', String.valueof(Date.daysInMonth(2015, 1))});
Where jan, feb, mar are Integer variables with your calculated number of days.