是否有库支持 Guava 表转 csv 格式? 我生成了
RowSortedTable<String, String, Double> graph
但是生成过程需要一些时间(需要一些查询处理),所以我想保存这个中间结果并想再次读取和使用它。
最佳答案
您可以使用Apache Commons CSV :
final RowSortedTable<String, String, Double> graph = TreeBasedTable.create();
graph.put("A", "0", 0.0);
graph.put("A", "1", 1.0);
graph.put("B", "0", 0.1);
graph.put("B", "1", 1.1);
final Appendable out = new StringBuilder();
try {
final CSVPrinter printer = CSVFormat.DEFAULT.print(out);
printer.printRecords(//
graph.rowMap().values()//
.stream()//
.map(x -> x.values())//
.collect(Collectors.toList()));
} catch (final IOException e) {
e.printStackTrace();
}
System.out.println(out);
// 0.0,1.0
// 0.1,1.1
关于java - 有库支持 Guava 表转 csv 格式吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32739028/