Dynamic Arraylists Creation and Detection


  •  I have a program which required number of arraylists to get data in some manner. like number of keywords in dynamic number of files. Now how I can create dynamic arraylists  and how I can detect and fill them programatically?

    Thanks in Advance!=)
    Saturday, July 26, 2008 11:06 PM


  • I'm not entirely sure I follow you here, but I'll take a stab at it.  First thing you need is somewhere to store your ArrayLists.  I like List<> for this purpose.  Then, creating one is relatively simple.

                //List to hold the ArrayLists  
                List<ArrayList> myArrays = new List<ArrayList>();  
                //used to generate random numbers  
                Random rnd = new Random();  
                //create a random number of ArrayLists  
                int totalArrayLists = rnd.Next(10);  
                for (int i = 0; i < rnd.Next(10); i++) {  
                    ArrayList arr = new ArrayList();  
                    //add a random number of items.  
                    int totalItems = rnd.Next(100);  
                    for (int j = 0; j < rnd.Next(100); j++ ) {  
                    //add the new ArrayList to the list of arraylists.  

    You can of course, ignore all of the random number stuff, that's just to simulate the unknown nature of your situation.
    • Marked as answer by Figo Fei Wednesday, July 30, 2008 2:56 AM
    Sunday, July 27, 2008 2:35 AM