Determining missing data
<p>I have text file.  It contains delimited data in each line like, </p>

<pre><code>120 US 1 ALASKA 4.
</code></pre>

<p>in some lines some data are missing. like, </p>

<pre><code>US 1 ALASKA 4
</code></pre>

<p>Since it is delimited by space, i am using split to get the tokens.  I am not able to determine which data is missing.</p>

<p>In the below code, sample input1 will validate <code>120</code> for <code>^[1-9]+$</code>. If the <code>120</code> is missing in the line, as in sample <code>input2</code>, the <code>token[0]</code> will have <code>US</code>, It will validate for <code>^[1-9]+$</code> and give <code>"Error in a"</code>.  Instead of this, i want to know which value is missing.  So, that i can display the error <code>"Error a i missing"</code> and the <code>token[1]</code> should contain <code>US</code>, so that i can validate correctly.</p>

<p>Can someone give some idea for doing the above?   </p>

<pre><code>        String line = "120 US 1 ALASKA 4"; //Sample input1
       //String line = "US 1 ALASKA 4"; //Sample input2
        String delimiter = "[ ]+";
        String tokens[] = line.split(delimiter);

        String a = tokens[0];
        String b = tokens[1];
        String c = tokens[2];
        String d = tokens[3];
        String e = tokens[4];

        //Sample validation
        if(a.matches("^[1-9]+$")){
           System.out.println("Matches");
        }else{
           System.out.println("Error in a");
        }        
</code></pre>
