Java 8:以数据表的形式存储和检索数据

Nib*_*bor 1 java datatable store java-8

我想以数据表的形式存储数据,如下所示:

+--------+-------+-----+-----+
|        |   s1  |  s2 |  s3 |
+--------+-------+-----+-----+
|   c1   |   5   |  7  |  7  |
+--------+-------+-----+-----+
|   c2   |   1   |  6  |  9  |
+--------+-------+-----+-----+
|   c3   |   0   |  9  |  6  |
+--------+-------+-----+-----+
Run Code Online (Sandbox Code Playgroud)

在java中存储它的好方法是什么,这样我就可以通过它们的密钥来检索数据.

我需要一个看起来像这样的方法:

public int getData(String row, String column);

// Example:
int i = getData("c1", "s1") // Would return 5
Run Code Online (Sandbox Code Playgroud)

acl*_*kay 6

你可以使用番石榴

https://github.com/google/guava/wiki/NewCollectionTypesExplained#table

Table<String, String, Integer> records = HashBasedTable.create();
records.put("s1","c1",5);
records.put("s3", "c3", 6);

Integer val = records.get("s1","c1"); // val = 5
Run Code Online (Sandbox Code Playgroud)