This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

how to store data in multi dimenstional arrays

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

can anybody tell me ..how to store and retrieve the data from multidimensional arrays ..is there any class or method i can use ..?
Thanks
karan
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. A multi-dimensional array is simply an array of arrays. Check out this code...it should help you figure out multi-dimensional arrays really quick if you run it!

As you can see, your arrays can be of varying lengths. Stare at the output of this program for awhile, then play around with it. It'll become clear after awhile. Hope this helps!
 
Karan Raj
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,

thanks for your inputs.My actual problem is....I don't know the length of the data i want to store. For my purpose i used Vectors for storing.This is the sample code i used for it.
Vector v=new Vector(2,3);
Object temp[]={"ADD332343",new Integer(230),new Double(3.22),
new Integer(22)}

v.addElement(temp);

Object t;
t=v.elementAt(0);

but how i can i refer to the individual elements in the "t"...? .
please help me...i am just learning java
Thanks
Karan
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once you pull something out of a Vector, you have to cast it to the proper type before you can use it:

You could also combine the get and cast into one line:
Object[] tArr = (Object[])v.elementAt(0);
Obviously if the first element of "v" was something other than an Object array you would get a class cast exception.
 
Karan Raj
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks jhonson, your solution is simple and easy
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!