array in a arraylist

  • Thread starter Thread starter Ricardo
  • Start date Start date
R

Ricardo

how can i acess the members of an array that i put into a arraylist, like
this:

int[] dez = new int[5];
ArrayList arList = new ArrayList();
arList.add(dez);

I want to get the dez[3] value.


[]s...
 
Hi

Use Jagged Arrays . Jagged arrrays are nothing but arrays of arrays.

Ravikanth[MVP]
 
Yes, but i don´t know how many arrays i will need to use, and a jagged array
i must initialize with a static lenght.

Ravikanth said:
Hi

Use Jagged Arrays . Jagged arrrays are nothing but arrays of arrays.

Ravikanth[MVP]


Ricardo said:
how can i acess the members of an array that i put into a arraylist, like
this:

int[] dez = new int[5];
ArrayList arList = new ArrayList();
arList.add(dez);

I want to get the dez[3] value.


[]s...
 
I think what he ment was something like

int[] dez = new int[5];
ArrayList arList = new ArrayList();
arList.add(dez);

--> arList[0][3] <--

Ricardo said:
Yes, but i don´t know how many arrays i will need to use, and a jagged array
i must initialize with a static lenght.

Hi

Use Jagged Arrays . Jagged arrrays are nothing but arrays of arrays.

Ravikanth[MVP]


Ricardo said:
how can i acess the members of an array that i put into a arraylist, like
this:

int[] dez = new int[5];
ArrayList arList = new ArrayList();
arList.add(dez);

I want to get the dez[3] value.


[]s...
 
ArrayLists store objects. You just have to cast the arraylist member object
as an int array:

ArrayList al = new ArrayList();

int[] ar = new int[] {1, 3, 5, 7,9};

al.Add(ar);

Console.WriteLine("ar[2] = {0}", ((int[])al[0])[2]);

I don't know if that's the only or the easiest way to do it, but the concept
remains the same. Cast the object as an integer array.



Dale



Ricardo said:
Yes, but i don´t know how many arrays i will need to use, and a jagged array
i must initialize with a static lenght.

Hi

Use Jagged Arrays . Jagged arrrays are nothing but arrays of arrays.

Ravikanth[MVP]


Ricardo said:
how can i acess the members of an array that i put into a arraylist, like
this:

int[] dez = new int[5];
ArrayList arList = new ArrayList();
arList.add(dez);

I want to get the dez[3] value.


[]s...
 
Back
Top