File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

dynamic Array

 
Raghuveer Rawat
Ranch Hand
Posts: 102
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Michael Morris
Ranch Hand
Posts: 3451
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about a List of Lists?

You can contiue adding new lists as necessary. To get a particular element you can:
 
Raghuveer Rawat
Ranch Hand
Posts: 102
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic