一、简介
如同之前所说的Multimaps工具类一样,Guava也为新的集合类型 - Table提供了专属的工具类 - Tables.这里也提供了一些比较实用的方法.
二、常用方法
1、Table行、列顺序调换方法 - transpose()
Tables提供了将原有Table<R, C, V>作为Table<C, R, V>视图的方法
实验代码:
Table<String, String, Integer> testTable = TreeBasedTable.create();
testTable.put("rowKey1", "columnKey1", 1);
System.out.println("=============测试transpose前数据为===================" + testTable);
Table<String, String, Integer> transpose = Tables.transpose(testTable);
System.out.println("=============测试transpose后数据为===================" + transpose);
testTable.put("rowKey1", "columnKey1", 2);
System.out.println("=============测试transpose后数据引用被修改的结果===================" + transpose);
实验结果:
=============测试transpose前数据为==================={rowKey1={columnKey1=1}}
=============测试transpose后数据为==================={columnKey1={rowKey1=1}}
=============测试transpose后数据引用被修改的结果==================={columnKey1={rowKey1=2}, columnKey2={rowKey1=3}}
可以发现输入的视图与预期一致
未完待续......






网友评论