title: index out of bound exception in java when accessing index of list
body: <p>I have a list and when I try to access the index of that list it gives index out of bound exception and when I print the value of that index in another method ,Its showing the result I can't understand when value is there at that particular index why <strong>java.lang.IndexOutOfBoundsException: Index: 0, Size: 0</strong> is thrown.</p>
  
  <p>My java code is-</p>
  
  <pre><code>public  List&lt;Vacc_vs6&gt; refarray_vac1(String fdate,String ldate) throws SQLException, ParseException {
  
              st_jsp.clear();
  
  
             try
                  {  
                    con = getConnection();
                    stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
  
  
                           String vs1= "sql query";
  
                    stmt.executeQuery(vs1);
                     rs = stmt.getResultSet();
  
                     while (rs.next()) {
                         Vacc_vs6 ref = new Vacc_vs6();
  
                            ref.setLogtime(rs.getString(1));
                            ref.setBeam_current(rs.getString(2));
                            ref.setBeam_energy(rs.getString(3));
                            ref.setst4_vs6_bag1_rb(rs.getString(4));
                            ref.setst4_vs6_bag2_rb(rs.getString(5));
                            ref.setst4_vs6_bag3_rb(rs.getString(6));
                            ref.setst4_vs6_bag4_rb(rs.getString(7));
                            ref.setst4_vs6_bag5_rb(rs.getString(8));
                            ref.setst4_vs6_bag6_rb(rs.getString(9));
                            ref.setst4_vs6_bag7_rb(rs.getString(10));
                            ref.setst4_vs6_bag8_rb(rs.getString(11));
                            ref.setst4_vs6_bag9_rb(rs.getString(12));
                        st_jsp.add(ref);
  
                      }
  
                  }
             catch( Exception e )
                      {
              System.out.println("\nException in refarray_vac1 "+e);
                      }
             List&lt;Vacc_vs6&gt; new_list=new ArrayList&lt;Vacc_vs6&gt;();
              double is = 9.5;
               double js = 10.5;
               int no=0;
          for(no=0;no&lt;=10;no++)
              {
                  String i= st_jsp.get(no).getBeam_current();//**Showing exception here**
                  double im = Double.parseDouble(i) ;
                  if(im&gt;is &amp;&amp; im&lt;js) 
                   {
                      new_list.addAll(st_jsp);
                   }
                  else
                  {
                      new_list.addAll(st_jsp);
                  }
                   is +=10;js +=10; 
  
                  }
  
             return st_jsp;
            }
  </code></pre>
  
  <p>When I define another method </p>
  
  <pre><code>public String get_Array()
  {  
  
   List&lt;Vacc_vs6&gt; new_list=new ArrayList&lt;Vacc_vs6&gt;();
  String i= st_jsp.get(0).getBeam_current();
  
  System.out.println("noeee"+i);
  return i;
  }
  </code></pre>
  
  <p>Then value is being printed at 0 index.<strong>Then Why exception is thrown when i run the above method??</strong></p>
  
  <p>Edit-1</p>
  
  <p>I did corrected it with <strong>st_jsp.size()</strong>.But according to <code>if(im&gt;is &amp;&amp; im&lt;js)</code> loop if the value at first index is not between given number then it should go to else and 0 should be added at that partiular position.But its not happening .
  Now <strong>IndexOutOfBoundsException</strong> exception is not occurring.</p>