How do I check if a variable has been initialized
<p>First of all, I'm fairly new to Java, so sorry if this question is utterly simple.</p>

<p>The thing is: I have a <code>String[] s</code> made by splitting a String in which every item is a number. I want to cast the items of <code>s</code> into a <code>int[] n</code>.</p>

<p><code>s[0]</code> contains the number of items that <code>n</code> will hold, effectively <code>s.length-1</code>. I'm trying to do this using a foreach loop:</p>

<pre><code>int[] n;
for(String num: s){
    //if(n is not initialized){
        n = new int[(int) num];
        continue;
    }
    n[n.length] = (int) num;
}
</code></pre>

<p>Now, I realize that I could use something like this:</p>

<pre><code>int[] n = new int[(int) s[0]];
for(int i=1; i &lt; s.length; i++){
    n[i-1] = (int) s[i];
}
</code></pre>

<p>But I'm sure that I will be faced with that "if n is not initialized initialize it" problem in the future.</p>
