-2

The question is not too dificult: How do I best implement a table in Java.

I wish to have something like a table in a database. Named columns and numbered rows. My values are Integer.

My inital idea: LinkedHashMap<String, ArrayList<Integer>>

But is there a better way of doing it?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
BrainStone
  • 3,028
  • 6
  • 32
  • 59
  • 1
    ...considered using a real database? SQLite is fantastically easy to use if you just need a simple database. – nneonneo Sep 02 '13 at 18:04
  • Why `LinkedHashMap` instead of `HashMap`? You don't need to ensure the order. – MD Sayem Ahmed Sep 02 '13 at 18:05
  • @SayemAhmed I would like to have it ordered. @ nneonneo Sounds not to bad. Do you have any good tutorials? (I can google myself but it's wasted time if you know something) – BrainStone Sep 02 '13 at 18:05
  • Isn't there a table structure in the Framework? – Geeky Guy Sep 02 '13 at 18:05
  • Take a look at [this](http://stackoverflow.com/questions/1340283/datatable-equivalent-in-java) and [that](http://stackoverflow.com/questions/1194971/dataset-class-in-java). – Geeky Guy Sep 02 '13 at 18:06
  • It seems that you've build a column-based structure. To access an entry you need to run `table.get("columnName").get(15)`. Do you need a table? – Piotr Gwiazda Sep 02 '13 at 18:10
  • Why do want to remodel the database table in java? Use ORM – Stimpson Cat Jun 06 '18 at 09:36

1 Answers1

2

What do you mean by "better"? It depends on what do you need to do with that.

You may build

  • a 2-dimensional array and a map of column names (C++ way)
  • a list of objects, where each object is a row (the most Java way)
  • a Guava Table
Piotr Gwiazda
  • 12,080
  • 13
  • 60
  • 91