我正试图将番石榴表导出为CSV。下面的代码可以工作,但它跳过了我想在输出中看到的第一列。你能提出什么建议吗?番石榴表格CSV CSV文件
编辑:显然使用values()
和keySet()
分开工作。
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);
编辑:这不起作用或者:
printer.printRecords(//
graph.rowMap().entrySet().stream().map(entry -> {
List a = Arrays.asList(entry.getKey());
a.addAll(entry.getValue().values());
return a;
}).collect(Collectors.toList())
);
你调试代码,检查该列是否仍然存在在传递给打印机的列表中还是不? – Thomas
'CSVPrinter'和'CSVPrinter'从哪里来? –
您的代码在第一行打印“0.0,1.0”,第二行打印为“0.1,1.1”,您的输出是什么? – Xaerxess