relation between Arraylist and ArrayIndexOutOfBoundsException
<p>What is the relation between <strong>List and Array</strong>. Why i am getting ArrayIndexOutOfBoundsException.?</p>

<blockquote>
  <p>Basically i am passing one argument to a method, based on that using HQL, i am returning one set of <strong>ArrayList</strong>. Now my problem is that. when this ArrayList returns more than 0 (size)  this is working exactly the way i want.</p>
  
  <p>But when it returns 0 (size) ArrayList, i am getting Exception.  why is that. can any body explain to me <br/>
  <br/></p>
</blockquote>

<p>Now i got one more doubt like if an arraylist returns 5(first) &amp; 0(second as size i tested up to) i am not getting any Exception. but when it returns like 200 or more elements its getting exception. why is that? <strong>Is there any specific constant no. like up to this many elements array shouldn't give IndexOutofBounds and things like that</strong>? can any body explain to me?<br/><br/></p>

<p>here is my code: </p>

<pre><code>  public void setUpDisplay()
  {
    if (_flatView || _expired || _issue){ // these are all my views.
        _deptBalances = fetchBalances(null);
    }
    else if (_searchGen.getGenericName() != null){ 
        _storeGenList.clear();
        _deptBalances = fetchBalances(_searchGen.getGenericName());
        if (!ListUtil.nullOrEmptyList(_deptBalances)){
            // i am displaying the result here.
        }
        else {
            displaying error message.
        }
    }
      // here i am using my _deptBalances to display(i am just putting this list into displaygroup).
} 
</code></pre>

<p>// here is my method.</p>

<pre><code>    public List&lt;DEPTStoreBalance&gt; fetchBalances(String genName){
    EntityManager em // Creating instance to entity manager.
    List &lt;DEPTStoreBalance&gt; tempList = ListUtil.list();
    String expClause =  new String();
    if (_expired){
        expClause = "and gg.bSubjectToExpiration=true " +
                    "and msb.expirationDate &lt;= :expDate ";
        if(_expiringOnly){
            expClause = expClause.concat(" and msb.expirationDate &gt; :today");
        }
        else {
            expClause = expClause + 
                        "and (msb.expirationDate &gt; :today " +
                        "or (balance.qtyBalance &gt; 0 or balance.qtyInTransit &gt; 0)) ";
        }
    }
    else {
        expClause = "and ((gg.bSubjectToExpiration=true " +
                    "and msb.expirationDate &gt; :expDate) " +
                    "or gg.bSubjectToExpiration=false) ";

        if (_flatView || _issue){
            expClause = expClause.concat("and (balance.qtyBalance &gt; 0 or balance.qtyInTransit &gt; 0) ");
        }
        else if (genName != null){
            expClause = expClause.concat("and gg.genericName = :genName ");
        }
    }

    String hql = "select balance from DEPTStoreBalance as balance " +
                 " "+ // here are my joins with multiple tables.
                 "where dsg.store = :store " +
                 expClause;

    if (_issue)
        hql = hql.concat(" and dsi.deptIssue = :deptIssue");
    Query q = em.createQuery(hql);
    q.setParameter("store", _store); // here i am selecting the store(which is being changing in search component).
    if (_issue)//Only saleable items should be issued
        q.setParameter("expDate",12 months);
    else 
        q.setParameter("expDate",_minExpDate ); // constant value :3
    if (_expired)
        q.setParameter("today", new Date());
    if (genName != null){
        q.setParameter("genName", genName);
    }
    if (_issue)
        q.setParameter("deptIssue", true);

    try{
        tempList = (List &lt;DEPTStoreBalance&gt;) q.getResultList();
    }
    catch (NoResultException nre){
        //do something
    }
    finally {
        em.close();
    }       
    return tempList;        
}
</code></pre>
