Java |从行键获取列键

Java | Get column keys from a row key

我 Table 喜欢 Table<String, String, String> distributions = HashBasedTable.create();

|----------------------------------------------|
| Row             | Column   | Value           |
|----------------------------------------------|
| aaa             | a        | Hard Rock       |
| aaa             | n        | Art Pop         |
| abc             | b        | Surrealist Film |
| abc             | c        | Blockbuster     |
|----------------------------------------------|


我的 Column 值都是唯一的,但我的 Row 值可以重复。

所以我怎样才能得到所有 Column 给定 Row 密钥的密钥?

如果您想要基于的值。它会给你多个值

您可以使用 Table.rowMap() to get "a view that associates each row key with the corresponding map from column keys to values"; the view is a Map and its keySet() 包含给定 Row 键的所有 Column 键:

 distributions.rowMap().get("aaa").keySet(); // [a, n]
 distributions.rowMap().get("abc").keySet(); // [b, c]