quick question about 2 Dimensional ArrayList in Java

soccerbud34

Senior member
Nov 15, 2001
747
0
0
Is there a method that makes it possible for one person retrieve one element but not one whole row of elements in 2 dimensional arrayLists?


thanks
 

soccerbud34

Senior member
Nov 15, 2001
747
0
0
tried it ... but for some reason, the double brackets [][] does not work on arrayLists ... or i did not do the [][] the right way

i.e. i tried myWords[f][g] (where both f and g are integers ) and i got an error saying " array required but java.util.arrayList found"

any ideas why?

edit** sorry if i misinformed you guys, but i am talking about 2D ArrayLists but not 2D arrays ... i know howt to access cells in 2D arrays :)**

thanks!
 
Jun 18, 2000
11,220
783
126
I'm unfamiliar with Java, but there should be a way to access any cell in the array with bracketed arguments. For example, you have an array variable called my2dArray. You could access individual cells with "[]". Like so:

my2dArray[12][10];

.. would give you the contents of the cell in the 13th row and 11th column (maybe 12th and 10; are indexes zero-based like in C?).

Edit: I type slowly.
 

Ameesh

Lifer
Apr 3, 2001
23,686
1
0


<< tried it ... but for some reason, the double brackets [][] does not work on arrayLists ... or i did not do the [][] the right way

i.e. i tried myWords[f][g] (where both f and g are integers ) and i got an error saying " array required but java.util.arrayList found"

any ideas why?

edit** sorry if i misinformed you guys, but i am talking about 2D ArrayLists but not 2D arrays ... i know howt to access cells in 2D arrays :)**

thanks!
>>



oh i see its a class not an array,

well you could do two get operations like ((arrayList)foo.get(f)).get(g)

thats should do it fine.