在内存中存储二维表结构的合适数据结构是什么?
我有一个从底层数据库读取的二维表结构,我想知道用于存储它的最佳内存数据结构是什么。 在哪里,可以访问它以供进一步阅读、操作等。
I have a 2D table structure that I am reading from an underlying database, and I am wondering, what is the best in-memory data-structure to use to store it into.
Where, it can be accessible for further reading, manipulation, etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在我看来,这样的事情通常是代码异味。您可能需要考虑创建一个代表表上行的 bean,并使用
List
而不是一些通用的表恐怖。当然,这假设您事先知道表格是什么样子。
In my opinion, things like this are often code smell. You might want to consider creating a bean that represents a row on a table and using
List<MyBean>
instead of some generic table horror.Of course this assumes you know what the table looks like beforehand.
Guava 库对 有两种不同的实现Table接口:
HashBasedTable
和TreeBasedTable
。你应该看一下。Guava libraries has two different implementations for the Table interface:
HashBasedTable
andTreeBasedTable
. You should take a look.哈希映射数组,键控列名称 =>价值对我来说很有意义。
An array of hashmaps keyed column name => value makes sense to me.
我会做地图的地图,就像
下面是一个例子
所以在你读完表格后,你可以像这样使用它:
希望这有帮助。
注意:我选择第一个映射的键为字符串,因为您的表可能没有整数作为 ID。如果您认为 Integer 更适合,您可以更改它们。
I would do maps of maps something like
Here is an example
So after you read the table you use it like this:
Hope this helps.
Note: I chose the first map to have a key of string because your table may not have integers as IDs. You can change them if you think Integer would fit better.