I am practising java which is new for me and learned recently about collections in java. I want to parse a csv file and store it on a hashmap. Also , I don't want to use any parser.
My CSV file:-
id,date,ministry,questions
2011,15.02.2014,HEALTH,What was the outcome
20757,24.02.2015,"DEFENCE , FINANCE" ,"Your budget this year .."
20113,17.03.2013,HEALTH, Hospitals build
So , I have few questions:-
- I want to have
"DEFENCE , FINANCE"
in same column. How will I use regex to remove "," so that , separator doesn't set new column - I want to display number of question asked in each ministry department. Here ex:- HEALTH have total 2 questions etc.
- Also no duplicates.
I am parsing through I/O filereader.
My code:-
public class MainData {
public static void main(String[] args) throws IOException ,FileNotFoundException{
String line = "";
String cvsSplitBy = ",";
try{
BufferedReader br = new BufferedReader(new FileReader("src/main/resources/rj.csv"));
HashMap<String,String> rjFile = new HashMap<String, String>();
System.out.println("running"+rjFile);
while ((line = br.readLine()) != null) {
String[] rj = line.split(cvsSplitBy);
System.out.println(br);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
PS:- I wan to use only map related collections.