Note that there are some explanatory texts on larger screens.

plurals
  1. POPopulate String[7] with data even if I don't have 7 items from my parser?
    primarykey
    data
    text
    <p>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.</p> <p>My data looks like this: </p> <blockquote> <p>Brenda Mines Snow Pillow,2013-11-26 04:00:00,-2.943,364,59,,</p> </blockquote> <p>or this:</p> <blockquote> <p>Barnes Creek Snow Pillow,2013-11-26 04:00:00,-6.6,344,117,10,12.97</p> </blockquote> <p>or possible other variations missing other columns. </p> <p>How do I always make my final <code>String[] data;</code> have 7 items in it? </p> <pre><code>data[0] through data[6] </code></pre> <p>I have tried an <code>if(data[i] == null){data[i] = "0";}</code> 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. </p> <p>I tried creating another array and adding the items in there and then if an item from <code>data[i] was null, data2[i] = "0" else data[i] = data2[i];</code> However, data[i] might not exists... I am just confused on how to make my array always contain 7 items.</p> <p>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"} </p> <p><strong>EDIT: I checked to make sure data.length was 7... it was, so what the problem was: <a href="https://stackoverflow.com/questions/9444638/null-vs-empty-string">NULL vs empty string</a> is answered here.</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload