Reputation: 1163
I'm stuck with the follwoing problem: I want to use guava tables as they provide a convenient transpose operation. In Java 8 a guava table can be instanciated like this:
Table<R,C,V> table = HashBasedTable.createTable();
All examples I found use static instanciation concerning the types and the number of columns. Unfortunately, I do not know the number of columns at design time, so I have to find a way to instanciate the Table with arguemtns which I have to determine at run time.
Any ideas?
Upvotes: 2
Views: 454
Reputation: 1163
Ok, I found it out myself, I misunderstood the documentation:
First I thought, a guava Table is instanciated like:
Table<T,....,T> table = HashBasedTable.createTable();
With N type definitions for each column.
But Reading the documentation more carefully, I found out that the instanciation is done by
Table<R, C, V> table = HashBasedTable.createTable();
Where R is the type of the row key, C type column key, V value type. Hence one can for instance instanciate a matrix of Double values via:
Table<Integer, Integer, Double> matrix = HashBasedTable.createTable();
and access the matix via the cell indices (Integer, Integer).
Upvotes: 1