Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array

 
popoe shi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
 
popoe shi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
popoe shi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
m~m~
I see~~
thank you!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic