Java ArrayList of Strings Throwing ArrayIndexOutOfBoundException : <p>Here is my problem:</p>

<ol>
<li><p>I have a Java String returned from my Web service in the below form:</p>

<p>21,6.417,0.3055714,27,0.7778,0.04761905</p></li>
<li><p>Now I have splitted this string into separate Strings by using split function by comma delimiter.</p>

<p>dataList = Arrays.asList(data.split(","));</p></li>
<li><p>I need to loop through this list and assign these Values into separate Strings like below:</p>

<pre><code>int playsCount = Integer.parseInt(dataList.get(0));
float sumTimeViewed = Float.valueOf(dataList.get(1));
float avgTimeViewed = Float.valueOf(dataList.get(2));
int loadsCount = Integer.parseInt(dataList.get(3));
float loadPlayRatio = Float.valueOf(dataList.get(4));
float avgViewDropOff = Float.valueOf(dataList.get(5));
</code></pre></li>
<li><p>Now While getting the values and assigning to the Individual int and floats, getting ArrayIndexOutofBoundsException. This is because some times the list is returning the size as 4 than 6. Here is the code:</p>

<pre><code>reportDataList = getReportData(entry.id);
    //System.out.println("reportDataList.size()"+reportDataList.size());
    if(reportDataList.size() &gt;= 1) {
        for(int i=0;i&lt;reportDataList.size();i++) { 
            if(!reportDataList.get(0).equals("")) {
                playsCount = Integer.parseInt(reportDataList.get(0));
                }
            if(!reportDataList.get(1).equals("")) {
                sumTimeViewed = Float.valueOf(reportDataList.get(1));
                }
            if(!reportDataList.get(2).equals("")) {
                avgTimeViewed = Float.valueOf(reportDataList.get(2));
                }
            if(!reportDataList.get(3).equals("")) {
                loadsCount = Integer.parseInt(reportDataList.get(3));
                }
            if(!reportDataList.get(4).equals("")) {
                loadPlayRatio =Float.valueOf(reportDataList.get(4));
                }
            if(!reportDataList.get(5).equals("")) {
                avgViewDropOff = Float.valueOf(reportDataList.get(5));
        }
        }
    }
</code></pre></li>
</ol>

<p>And here is the getReportData method:</p>

<pre><code>private List&lt;String&gt; getReportData(String id) throws KalturaApiException {
    List&lt;String&gt; headerList = null;
    List&lt;String&gt; dataList = new ArrayList&lt;String&gt;();
    ReportService reportService = client.getReportService();
    ReportType reportType = ReportType.TOP_CONTENT;
    ReportInputFilter reportInputFilter = new ReportInputFilter();
    reportInputFilter.fromDate = 1390156200;
    reportInputFilter.toDate = 1453660200;
    ReportTotal reportTotal = reportService.getTotal(reportType, reportInputFilter, id);
    String data = reportTotal.data;
    if(data != null) {
        dataList = Arrays.asList(data.split(","));
    }
    if(dataList.size() &gt;= 1) {
        System.out.println("dataList.size() -------&gt;"+dataList.size());
    }
    return dataList;
    }
</code></pre>

<p>How to resolve this problem for any List size acceptable?</p>

<p>Thanks in Advance
Raji</p>
