I am quite new to Java so this may be a naive question. I am trying to read a CSV file which each line looks like below:
1,"4CC0D97F9ECC6B1A","MUTSAARD","7",1,"7-8",0,0,"ACT"
I used the below code to read this line:
BufferedReader reader = new BufferedReader(new FileReader(attributesFile));
String agent = null;
while ((agent = reader.readLine()) != null) {
String[] attributeSpilted = agent.split(",");
String agentGender = attributeSpilted[4] == "1" ? "m" :"f";
System.out.println(agentGender);
// using a break here for test purposes, delete when finish in the future
break;
}
So ideally, as the 5th element in this line is 1, the agentGender
should be a String variable which ==
"m", however, after running this code it returns an "f".
I guess the problem is because there is no "" in the original data for the fifth element, but I don't know how should I fix this problem? In other words, what's the type of data when reading CSV elements without a quotation mark?