在内存中存储二维表结构的合适数据结构是什么?

发布于 2024-10-14 02:23:52 字数 71 浏览 11 评论 0原文

我有一个从底层数据库读取的二维表结构,我想知道用于存储它的最佳内存数据结构是什么。 在哪里,可以访问它以供进一步阅读、操作等。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

∞觅青森が 2024-10-21 02:23:52

在我看来,这样的事情通常是代码异味。您可能需要考虑创建一个代表表上行的 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.

寻梦旅人 2024-10-21 02:23:52

Guava 库对 有两种不同的实现Table接口:HashBasedTableTreeBasedTable。你应该看一下。

Guava libraries has two different implementations for the Table interface: HashBasedTable and TreeBasedTable. You should take a look.

鹿! 2024-10-21 02:23:52

哈希映射数组,键控列名称 =>价值对我来说很有意义。

An array of hashmaps keyed column name => value makes sense to me.

粉红×色少女 2024-10-21 02:23:52

我会做地图的地图,就像

Map<String, Map<String,String>> table = new HashMap<String, Map<String,String>>();

下面是一个例子

column_a(primary),  column_b,  column_c
--------------------------------
abc              |  xyz      | 123
def              |  xxx      | 456

所以在你读完表格后,你可以像这样使用它:

map.get("abc").get("column_b").equals("xyz")
map.get("def").get("column_c").equals("456")

希望这有帮助。
注意:我选择第一个映射的键为字符串,因为您的表可能没有整数作为 ID。如果您认为 Integer 更适合,您可以更改它们。

I would do maps of maps something like

Map<String, Map<String,String>> table = new HashMap<String, Map<String,String>>();

Here is an example

column_a(primary),  column_b,  column_c
--------------------------------
abc              |  xyz      | 123
def              |  xxx      | 456

So after you read the table you use it like this:

map.get("abc").get("column_b").equals("xyz")
map.get("def").get("column_c").equals("456")

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文