File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array" Watch "Array" New topic
Author

Array

popoe shi
Greenhorn

Joined: Sep 14, 2003
Posts: 10
Hello~~
I want to being a three dimension,
but the sencond index I can not deside in advance.
This array will put large data,so the index should be exactly.
Can you have another class to slove this problem,
and please give me some example...
thank you!!
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Nothing to do with Servlets.
I'll move this to the Java in General (beginner) forum for you.
Dave
Donald R. Cossitt
buckaroo
Ranch Hand

Joined: Jan 31, 2003
Posts: 401

but the sencond index I can not deside in advance

What eventually decides the needed index? Is it another list, text file or DB?
You can measure the length of your list, file or DB at runtime:
int j = list.length() ; or file or record...
dimension[ i ][ j ][ k ]
Can you give an example?
[ September 15, 2003: Message edited by: Donald R. Cossitt ]

doco
popoe shi
Greenhorn

Joined: Sep 14, 2003
Posts: 10
First I get the data from database
and define an object,put the data into three dimention
Resultset rs = stmt.executeQuery();
Object a[][][] = new Object[x][y][z];
while(!rs.next())
{
i = rs.getObject("id").intvalue();
a[i][j][0] = 123;
a[i][j][1] = 234;
a[i][j][2] = 456;
j++;
}
x will put the kind value
y is the record number
z is the field
now I put j to the y place,j is the rownum,I can use rs.getRow() to get it,
but it will bring many null space,can you help me?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Java doesn't have any kind of "sparse" array that only uses storage for the entries that are filled. (I remember when that was a breakthrough in Lotus 1-2-3 for DOS.) Java reserves memory for all the squares on the board whether there are checkers there or not. Maybe you could use a Map instead?

Now the Map uses memory only for what you put in it. Plus the hashtable. Would that be easier to work with?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
popoe shi
Greenhorn

Joined: Sep 14, 2003
Posts: 10
m~m~
I see~~
thank you!!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Array