简体   繁体   中英

Java | Get column keys from a row key

I have Table like 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     |
|----------------------------------------------|


My Column values are all unique but my Row values can be repeated.

so How can I get all the Column keys given a Row key?

If you want values based on rows . it will give you multiple values

You can use 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() contains all of the Column keys for a given Row key:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM