I am populating a list array with lines from a csv file. I have some empty columns and some not. I would like these empty columns to contain "0" if they are empty. The length of the string[] could be 1 to 7. However, I need to return 7 items when all is said and done.
My data looks like this:
Brenda Mines Snow Pillow,2013-11-26 04:00:00,-2.943,364,59,,
or this:
Barnes Creek Snow Pillow,2013-11-26 04:00:00,-6.6,344,117,10,12.97
or possible other variations missing other columns.
How do I always make my final String[] data;
have 7 items in it?
data[0] through data[6]
I have tried an if(data[i] == null){data[i] = "0";}
but that doesn't work since my list from the parsed data may not have a length of i and I get a index OB error.
I tried creating another array and adding the items in there and then if an item from data[i] was null, data2[i] = "0" else data[i] = data2[i];
However, data[i] might not exists... I am just confused on how to make my array always contain 7 items.
Any help would be so great. I should add that I have tried to initialize first: String[] data = {"0","0","0","0","0","0","0"}
EDIT: I checked to make sure data.length was 7... it was, so what the problem was: NULL vs empty string is answered here.