Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

2D array

debraj mallick
Ranch Hand
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
Posts: 3174
34
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.

debraj mallick
Ranch Hand
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
Posts: 19
Check this out Coderanch: Multidimensional-ArrayList

-VS

John Jai
Rancher
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.

Campbell Ritchie
Sheriff
Posts: 55329
157
Vince Stout, welcome to the ranch and that is some good detective work finding that 9-year old thread.

Vince Stout
Greenhorn
Posts: 19
I've been watching a lot of Sherlock Holmes lately. ;)

debraj mallick
Ranch Hand
Posts: 188
thank you Vince Stout and John Jai.