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
vijendhar k 16vijendhar k 16 

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

Hi All,

  when to use nested list in salesforce
  can you please help understnd following list, adding data, iterating data for the follwing example
  List<List<list<Integer>>> my_list_2 = new List<List<list<Integer>>>();
  explain me to  nexted complete playing with any example please
Best Answer chosen by vijendhar k 16
JeffreyStevensJeffreyStevens
Each element of my_list_2 is a list<list<Integer>>.
 
for(list<list<integer>> mList2Lists :my_list_2) {
  // mList2Lists is a list<list<integer>>....
  for(list<integer> mList2List :mList2Lists) {
    // mList2List is list<integer>
    for(integer i :mList2List) {
      // i is an integer....
      system.debug('i='+i);
    }
  }
}

does that help?
 

All Answers

vijendhar k 16vijendhar k 16
If posible explain me with samll example :)
JeffreyStevensJeffreyStevens
Each element of my_list_2 is a list<list<Integer>>.
 
for(list<list<integer>> mList2Lists :my_list_2) {
  // mList2Lists is a list<list<integer>>....
  for(list<integer> mList2List :mList2Lists) {
    // mList2List is list<integer>
    for(integer i :mList2List) {
      // i is an integer....
      system.debug('i='+i);
    }
  }
}

does that help?
 
This was selected as the best answer
vijendhar k 16vijendhar k 16
Hi JeffreyStevens,
    
Thanks for Quick &Great response, i understand how to loop list with 3 level nested list with your example, if posible can you please give us example with adding data and looping data  with sobjects in salesforce, your work will be appreciable to improve my Devlopment knowledge

Thanks
 Vijay :)



 
  
  
 
JeffreyStevensJeffreyStevens
Ok - let me try...

Let's move the example from integer's to - strings.  Let's say that you want to hold a List<list<list<string>>> that represents Countries, States, Cities.  Say your data looks like this...  (and it would make more sense to use Maps in this case - but I'll stay with list<string>)

USA
  AK
    ACityName
    BCityName
  AL
    ADifferentCityName
    BDifferentCityName
 
list<string> cityNames = new list<string>();
cityNames.add('ACityName');
cityNames.add('BCityName');

list<string> cityNamesAL = new list<string>();
cityNamesAL.add('ADifferentCityName');
cityNamesAL.add('BDifferentCityName');

list<list<string>> StatesAndCities = new list<list<string>>();
statesAndCities.add(cityNames);
statesAndCities.add(CityNamesAL);

list<list<list<string>>> CountriesStatesAndCities = new list<list<list<string>>>();
CountriesStatesAndCities.add(statesAndCities);

I think that code would work - but I didn't test it.

Is that what you were looking for?  You might need to tell us more of what you're doing or trying to do.

 
vijendhar k 16vijendhar k 16
Hi jaffary,
   Thanks for reply, with that code i can only add citys, but if i want to add the list mentions like country==>state-->city into the list, how to write code as per your code i can see following output http://tinypic.com/r/hth4t1/9

 
Ramya Iswarya UppuRamya Iswarya Uppu
public class mapTest {
    public static void testingMap(){
        
        Map<string,list<string>> map1= new Map<string,list<string>>();
        list<string> list1= new list<string>();
        list1.add('Hyderabad');
        list1.add('Secendrabad');
        map1.put('Telengana', list1);
        
        Map<string,list<string>> map2= new Map<string,list<string>>();
        list<string> list2= new list<string>();
        list2.add('City1');
        list2.add('City2');
        map2.put('NewYork', list2);
        
        Map<string,list<string>> map3= new Map<string,list<string>>();
        list<string> list3= new list<string>();
        list3.add('Seoul');
        list3.add('South');
        map3.put('North_korea', list3);
        
        Map<string,Map<string,list<string>>> countryStateCity= new Map<string,Map<string,list<string>>>();
        countryStateCity.put('India',map1);
        countryStateCity.put('Us',map2);
        countryStateCity.put('North_korea',map3);
        System.debug(countryStateCity.get('India'));
        System.debug(countryStateCity.get('Us'));
        System.debug(countryStateCity.get('North_korea'));
    }
}