• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Two dimensional data structures?

 
John McGahee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you have a 2 dimensional Vector/ArrayList etc?
Is there a better(growable) substitute for say
String[][] strArray = new String[x][x];
or
Object[][] objArray = new Object[x][x]
???
-john
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi John,
i dont know if there is direct substitute but i guess if we use Hashtable, HashMap etc then we can consider it as "two dim" array, can't we?
each key in the hashtable is index of the row. and the value is the one dim array. right?
though i don't know how far this would be good to us.
more thoughts?
regards
maulin
 
Ellen Zhao
Ranch Hand
Posts: 581
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi John,
I think if isolated, it might be meaningless to say this data structure is good and that less good. It depends on what do you want to do with the data structure.
Relationship of general purpose data structure:
1.Small amount of data ? 2 : 3
2.Amount of data predicatable ? 4 : 6
3.Searching and insertion must be very fast ? 9 : 5
4.Search speed more important than insertion speed? 7 : 8
5.Key distribution guaranteed random? 10 : 11
6.Linked list
7.Ordered Array
8.Unordered array
9.Hash Table
10.Binary Search Tree
11.Balanced Tree

Relationship of external storage choice:
1. Speed important ? 2 : 4
2. Speed critical ? 3 : 5
3. Extra storage available ? 6 : 7
4. Sequential search
5. B-tree
6. External hashing
7. Indexed files
Concerning hash table, a hash table is based on an array. The range of key value is usually greater than the size of the array. A key value is hashed to an array index by a hash function. It�s not exactly like a two dimensional array but not necessarily better than a two dimensional array. Depends on what you want
Once you make your decision of what data structure to use, you can almost always invoke some worked packages to deal with it( I think most probably they would be in the Collection package in Java SDK ) or if you have much time, you can do all the low level constructions by yourself, algorithms available via google
Hope that could be of help.

Regards,
Ellen
[ January 17, 2003: Message edited by: Ellen Fu ]
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A List of Lists would be one way to do this. But if what you really want is a two-dimensional array, then just use that and manually resize your arrays as needed.
 
John Lee
Ranch Hand
Posts: 2545
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I am not mistaken, you have up to n-dimensinal array.
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java does not support n-dimensional arrays in the strict sense, but rather arrays of arrays (of arrays, etc.). A "true" n-dimensional array would enforce a single scalar for each dimension. That is, a 3 x 5 array would be a three-element array, where each element has 5 elements in the sub-array. Java does not enforce this behavior.
 
John Lee
Ranch Hand
Posts: 2545
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
But I guess I can still use a notation like:
A[9][7][4][6]
Can I?
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, you can.
 
John Lee
Ranch Hand
Posts: 2545
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic