function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Abc234Abc234 

How to add values to nested LISTs

Hi,

 

i am new to salesforce.

 

i have an doubt how to add values to the nested list

 i have declared a nested list(as below) then i need to add values to that nested

List<List<Integer>> my_list_2 = new List<List<Integer>>();

Regards,

Bharath

Best Answer chosen by Admin (Salesforce Developers) 
Damien_Damien_
List<List<Integer>> my_list_2 = new List<List<Integer>>();
List<Integer> tempList = new List<Integer>();
tempList.add(5);
my_list_2.add(tempList);

 

All Answers

Damien_Damien_
List<List<Integer>> my_list_2 = new List<List<Integer>>();
List<Integer> tempList = new List<Integer>();
tempList.add(5);
my_list_2.add(tempList);

 

This was selected as the best answer
Abc234Abc234

Thanks Damien,

 

But what is the difference between normal list and nested list

In both cases, we are adding single value means for nested i thought value like (i,j)

 

when i executed below code only differnce is DEBUG| (5) and DEBUG| ((5))

 

List<List<Integer>> my_list_2 = new List<List<Integer>>();
List<Integer> tempList = new List<Integer>();
tempList.add(5);
system.debug(tempList);

//above line gives USER_DEBUG|[4]|DEBUG|(5)
my_list_2.add(tempList);
system.debug(my_list_2);

//above line gives USER_DEBUG|[6]|DEBUG|((5))

 

 


NishaCNishaC

hii

i wanted to know

how to separate list<List<String>>

like i have used this map

Map<Id,List<List<String>>> servMap = new Map<Id,List<List<String>>>();

 

//implemented MAP

for(Service__c serObj: serviceList){
Id parentAccId = serObj.Customer__r.Grand_Parent_Account__c;
String AccountId = String.valueOf(serObj.Customer__r.id);
String count= String.valueOf(serObj.Count_of_Pickup_Days__c);
List<String> childDetailsList = new List<String>{AccountId, count};

if(serObj.Status__c == 'Active'){
if(servMap.get(parentAccId)==null)
{
servMap.put(parentAccId,new list<List<String>>{childDetailsList});
}
else
{
servMap.get(parentAccId).add(childDetailsList);
}
}
}

 

now i have this result through map...........parentID----->(ChildID,PickupDays) in debug

--servMap---{0012000000WekRxAAJ=((0012000000klmcVAAQ, 0), (0012000000oqfRSAAY, 1), (0012000000oqfRSAAY, 2), (0012000000eX4psAAC, 1), (0012000000eX4psAAC, 3), (0012000000cVX9hAAG, 2), (0012000000bGLicAAG, 1))}

now i want to get Pickup days values of all the child that are coming in debug like

0+1+2+1+3+2+1 = 10     total value

 

for(Id ParentAccountID:servMap.keySet()){
        List<List<String>> ChildList= servMap.get(ParentAccountID);
        System.debug('---ChildList---'+ChildList);
}

now the childList is coming with pickup days value in Debug and i want pickup days and SUM them

so tell me how to separate this List<List<String>>