• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

2D array

 
debraj mallick
Ranch Hand
Posts: 188
Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this out Coderanch: Multidimensional-ArrayList

-VS
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49841
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vince Stout, welcome to the ranch and that is some good detective work finding that 9-year old thread.
 
Vince Stout
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been watching a lot of Sherlock Holmes lately. ;)
 
debraj mallick
Ranch Hand
Posts: 188
Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you Vince Stout and John Jai.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic