• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Which data structure I have to use for table?

 
Alessandro Camel
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I need to use a table like this:

http://www.optizone.it/tgu.html


What kind of data structure is the best?
I doesn't need to be updated, I only need to read it!

Thanks!


 
Campbell Ritchie
Sheriff
Pie
Posts: 50278
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
List of Lists of Integers?
Array of arrays of ints?
You would have to pad those structures with 0s, and display the 0s as blanks, at least on their “left” side.

Can you change the entire table into a formula?
 
Alessandro Camel
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Can you change the entire table into a formula?


No, I can't! They are precalculated values!
I was thinking about a DB, but not sure about it.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50278
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don’t like that website. It told me that 100g pane di grano duro (bread from strong flour) contains 0 proteine and 6.6 carboidrati, which I am sure is incorrect.
 
Riaan Nel
Ranch Hand
Posts: 160
IntelliJ IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alessandro Camel wrote:
I was thinking about a DB, but not sure about it.

Are you asking about how your data should physically be stored on your hard drive or about how the data can be displayed in Java?
 
Alessandro Camel
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Riaan Nel wrote:
Alessandro Camel wrote:
Campbell Ritchie wrote:
I was thinking about a DB, but not sure about it.

Are you asking about how your data should physically be stored on your hard drive or about how the data can be displayed in Java?


To be honest... both! ;)
This is the first time I come across a structure like this and I am not sure how I should store and access it.
No need to be to display it! I only need to read it.
Also, keep in mind that I only need to access it once: so, maybe, loading in memory could be a waste of memory space.
 
Riaan Nel
Ranch Hand
Posts: 160
IntelliJ IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alessandro Camel wrote:
To be honest... both! ;)
This is the first time I come across a structure like this and I am not sure how I should store and access it.
No need to be to display it! I only need to read it.
Also, keep in mind that I only need to access it once: so, maybe, loading in memory could be a waste of memory space.

You can store it in a database, but you'll still need to put it in a format that Java can understand. I'd go for a JTable and a DefaultTableModel (since the data is not editable, use the constructor that takes a 2D* object array). This is assuming that you'll be displaying your data in a Swing app.

For the data to be displayed, it has to be in memory, so there's no way that you can get around that. After all, you can't display something that isn't there.

Edit: * Java doesn't have actual 2D arrays, it has arrays of arrays.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50278
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What’s a 2D array? Do you mean an array of arrays?

At this stage, I think this discussion might fit better in our GUIs forum, so I shall move it.
 
Riaan Nel
Ranch Hand
Posts: 160
IntelliJ IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:What’s a 2D array? Do you mean an array of arrays?

Noted, and fixed.
 
Cole Terry
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow! It's an awesome structure I have ever seen. I think it's quite different to implement such table structure with regular JTable.
I have one idea: create that table in HTML put the HTML code into a JTextPane. How does that sound?
 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Terrible. When you need to get the value of a specific cell you need to parse the entire HTML document.

Since the matrix is somewhat sparse, perhaps a Map<Point,Integer> is an option. The Point will contain the height and weight, but you must make sure that these Point objects never get modified, or they will no longer work correctly as Map keys. Alternatively you can create your own immutable class that represents the height and weight, and use instances of that as keys.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic