グアバテーブルをCSVにエクスポートしようとしています。以下のコードは動作しますが、出力に表示したい最初の列もスキップします。あなたは何かを提案できますか?グアバテーブルからCSVへ
EDIT:明らかに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);
EDIT:これはどちらか動作しません:テーブルの
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