Two Laptop Bag*
The moose likes Java in General and the fly likes dynamic Array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "dynamic Array" Watch "dynamic Array" New topic
Author

dynamic Array

Raghuveer Rawat
Ranch Hand

Joined: Apr 03, 2003
Posts: 102
hi
I java we do not have Multidimentional Array. instead we create Array of Arrrays.
I want to create a two dimentional array for storing database tables dynamically. Is there any solution for this problem.


Raghuveer Rawat<br />SCJP2
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
How about a List of Lists?

You can contiue adding new lists as necessary. To get a particular element you can:


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Raghuveer Rawat
Ranch Hand

Joined: Apr 03, 2003
Posts: 102
hi Michael
This will not solve my purpose. Actually I am creating a table dynamically.
JTable table = JTable(Object data[][],Object column[]);
for this I will have to pass 2D array in the first parameter of the JTable and this array will be generated dynamically.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Depends how dynamic you want this to be. If the numbers of rows and columns are variables, but they don't change after the table is created, then it's easy to use an array of array. E.g. for r rows and c columns, use
new Object[r][c]
However if the number of rows or columns needs to be able to change after the table is created, you should use a TableModel rather than an Object[][]. See the Java Tutorial on How To Use Tables for more info.


"I'm not back." - Bill Harding, Twister
 
 
subject: dynamic Array