Java Array split() displaying all values but giving arrayindexoutofbound exception error : <p>I am writing code to take input from a file which has records in a given format and then splitting them to display pincodes which i need to compare later and write the records. To do the comparision i am first taking all the pincode fields in the records and storing them in a array.I am able to display pincodes but there is an exception. My method code is below.</p>

<pre><code>String[] getPincodesArray(String filename) {



String[] st=new String[30];

int index=0;

try {

    FileReader fr=new FileReader(filename);

    BufferedReader br=new BufferedReader(fr);

    String line=br.readLine();

    while(line!=null) {

        String s[]=line.split(",");



        String s1[]=s[1].split(";");

        st[index]=s1[1];

        index++;

        line=br.readLine();




    }


}

catch(Exception e) {


    e.printStackTrace();
}

return st;
</code></pre>

<p>}</p>

<p>when i am executing this function is main(),I am getting an exception but am able to display all pincodes.The output is </p>

<pre><code>java.lang.ArrayIndexOutOfBoundsException: 1
at info.pack.Methods.getPincodesArray(Methods.java:270)
at info.pack.studentidpincode.main(studentidpincode.java:18)
</code></pre>

<p>560054
560076
560098
560054
560097
560087
560054
null
null
null..</p>

<p>I am able to see all pincodes, then why is the exception coming? </p>
