• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

2D array

 
Ranch Hand
Posts: 188
Hibernate Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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].
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check this out Coderanch: Multidimensional-ArrayList

-VS
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 80874
506
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you Vince Stout and John Jai.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic