import java.io.BufferedReader;
import java.io.FileReader;
import java.util.HashMap;
import java.util.Map;
public class CsvParser {
public static void main(String[] args) throws Exception {
String csvFile = "filename.csv";
String line = "";
String delimiter = ",";
String[] header = null;
Map<String, String[]> associativeArray = new HashMap<>();
BufferedReader br = new BufferedReader(new FileReader(csvFile));
while ((line = br.readLine()) != null) {
String[] row = line.split(delimiter);
if (header == null) {
header = row;
} else {
String[] data = new String[row.length];
for (int i = 0; i < row.length; i++) {
data[i] = row[i];
}
String key = row[0] + " " + row[1];
associativeArray.put(key, data);
}
}
br.close();
// Print the Associative Array
System.out.println("fname,lname,gender,email,telephone");
for (Map.Entry<String, String[]> entry : associativeArray.entrySet()) {
String[] data = entry.getValue();
for (int i = 0; i < data.length; i++) {
if (i == 0) {
System.out.print(data[i]);
} else {
System.out.print(delimiter + data[i]);
}
}
System.out.println();
}
}
}