0

let I have a hashmap HashMap. Now I want to write all the values row-wise into a CSV file

HashMap:
Key: BOF   Value: SAPF,754
Key: BOM   Value: SAPM,456
Key: BOL   Value: SAPL,987

I want to make a csv with this format:

SAPF,754
SAPM,456
SAPL,987

How to do it?

kalyan
  • 35
  • 1
  • 8
  • By writing some code, possibly helpeed by one of the dozens of libraries allowing to write CSV files in Java. Do some research, read documentation, and start trying something. Then come back here if you have a concrete question. – JB Nizet Sep 20 '17 at 11:16
  • You are expected to do **serious** research prior posting questions. It took me less than 3 seconds to identify multiple questions asking the very same thing... – GhostCat Sep 20 '17 at 11:17

1 Answers1

2

You can iterate through the entries and write to a file, e.g.:

Map<String, String[]> map = //Map with data
try(BufferedWriter writer = new BufferedWriter(new FileWriter("<your_file>"))){
    for(Map.Entry<String, String[]> entry : map.entrySet()){
        writer.write(String.join(",", entry.getValue()));
        writer.newLine();
    }
}
Darshan Mehta
  • 30,102
  • 11
  • 68
  • 102
  • Hi @Darshan ..thank you so much... writer.write(String.join(",", entry.getValue())); does this mean u r putting ',' as delimiter? – kalyan Sep 20 '17 at 11:35