Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning 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
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

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
 
What does a metric clock look like? I bet it is nothing like this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic