I try to read data from csv file, save it to linkedHashMap and print it. But the thing is that I neet print key and value separately. Csv file has just 2 columns: First: email, Second: name.
public class CsvReader {
String CSVPath = "c:/Users/PC/Desktop/file.csv";
CSVReader reader;
public void readCsvFile() throws IOException {
try {
reader = new CSVReader(new FileReader(CSVPath));
String[] column;
ArrayList<LinkedHashMap<String, String>> myArraylist = new
ArrayList<LinkedHashMap<String, String>>();
LinkedHashMap<String, String> map;
while ((column = reader.readNext()) != null) {
map = new LinkedHashMap<String, String>();
map.put("Emails", column[0]);
myArraylist.add(map);
}
reader.close();
for (int i = 0; i < myArraylist.size(); i++) {
System.out.println(myArraylist.get(i).get("Emails").toString());
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
When I run this code I get the following:
info@staybysantacruz.com;Quality Inn & Suites Santa Cruz Mountains
VacationRentals321@gmail.com;In Big Bear
info@haiyi-hotels.com;Best Western Americania
so it prints email and the name together. I tried to get to key and value of the linkedHashMap but with no luck. Could someone help me?