Guava Hashtable可以使用不同数据类型的列吗?

时间:2018-02-03 07:22:10

标签: java hashtable guava

我需要创建一个Guava Hashtable并在不同的列中存储整数和字符串值。可以用番石榴Hashtable完成吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

Take a look in Table documentation (HashBasedTable is only an implementation of Table - "...which is essentially backed by a HashMap<R, HashMap<C, V>>...")

A single Table<R, C, V> object represents a single mapping between a row key R, a column key C and a value V and as so, you can have only columns from a single type on a particular Table object.

To mixture columns you can create two table objects with shares the same keys: Table tableStringCol = HashBasedTable.create(); table.put(1, "doc_name", "Bill"); Table tableIntegerCol = HashBasedTable.create(); table.put(1, "doc_count", 10); table.put(1, "doc_size", 15);

You can also use a single Table object which have only String columns and then when fetching the values, make a conversion from the relevant columns into Integer. You can read more about Guava's Table here