| Author |
2D array
|
debraj mallick
Ranch Hand
Joined: Mar 08, 2011
Posts: 188
|
|
hi all,
i need a 2D array whose dimension is not fixed i.e. grow able 2D array or i can say infinite 2D array,
how to initialize it?
any help would be great.
|
 |
Mohamed Sanaulla
Bartender
Joined: Sep 08, 2007
Posts: 2926
|
|
An array would need to have a dimension specified, so I dont think you can create an infinite 2D array. You can search on this forum for more queries related to Two dimensional arrays.
But if you are looking for some structure whose size would increase dynamically- you can consider a ArrayList.
|
Mohamed Sanaulla | My Blog
|
 |
debraj mallick
Ranch Hand
Joined: Mar 08, 2011
Posts: 188
|
|
hi Mohamed Sanaulla,
thanks for the use link, should i use this to declare an infinite 2D array.
is there any way where i can obtain value in a perticular position like we do when using simple 2D array i.e. arr[59][987].
|
 |
Vince Stout
Greenhorn
Joined: Apr 13, 2012
Posts: 19
|
|
Check this out Coderanch: Multidimensional-ArrayList
-VS
|
-VS
Always consult the oracle before asking a question.
|
 |
John Jai
Bartender
Joined: May 31, 2011
Posts: 1776
|
|
debraj mallick wrote:hi Mohamed Sanaulla,
thanks for the use link, should i use this to declare an infinite 2D array.
is there any way where i can obtain value in a perticular position like we do when using simple 2D array i.e. arr[59][987].
This is not an Array. It's a Collection. What you have declared is a List that in turn holds a List capable of holding Strings.
You cannot directly query for [59][987]. First get the inner 59th ArrayList by using get() and another get() to retrieve the 987th String value from the inner List.
Read - http://docs.oracle.com/javase/6/docs/api/java/util/ArrayList.html
And there is no 2D, 3D arrays in Java. Read Stephen's reply in this thread.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32651
|
|
Vince Stout, welcome to the ranch and that is some good detective work finding that 9-year old thread.
|
 |
Vince Stout
Greenhorn
Joined: Apr 13, 2012
Posts: 19
|
|
|
I've been watching a lot of Sherlock Holmes lately. ;)
|
 |
debraj mallick
Ranch Hand
Joined: Mar 08, 2011
Posts: 188
|
|
|
thank you Vince Stout and John Jai.
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: 2D array
|
|
|