it might sound stupid. I am trying to read and process the data from a CSV file. I save the first line into a String array(things such Year, Month, Day, First name, Second name, date of birth, nationality). Well For example I need just Year, date of birth, and the First name. As I have many CSV files, and the order of the header(the first line) is changing I have to link some variables with the position of the Year, date of birth and first name from the array. So I tryed a lot of posibilities. One of them is here:
int indexYear = 0;
int indexMonth = 0;
int indexDay = 0;
int indexFirstname = 0;
int indexSecondname = 0;
String strForFirstLine="";
strForFirstLine += input.readLine();
String getFirstLine[] = strForFirstLine.split(",");
for(int i=0; i<getFirstLine.length; ++i){
if(getFirstLine[i].equals("'Year'"))
indexYear = i;
if(getFirstLine[i].equals("'Month'"))
indexMonth = i;
if(getFirstLine[i].equals("'Day'"))
indexDay = i;
if(getFirstLine[i].equals("'Firstname'"))
indexFirstName = i;
if(getFirstLine[i].equals("'Secondname'"))
indexSecondName = i;
}
Thanks in advance :).
output for getting the SecondName from an arrayList:
The output for getting the firstName: 'code' run:
"2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" "2012/3" null BUILD SUCCESSFUL (total time: 0 seconds)