title: How to use subList()
body: <p>I have a JSF page which displays list of Glassfish log files. I use lazy loading for pagination. I keep the list of the log files names into Java <code>List</code>.</p>
  
  <pre><code>private List&lt;directoryListObj&gt; dataList = new ArrayList&lt;&gt;();
  
  dataList = dataList.subList(firstRow, lastRow);
  </code></pre>
  
  <p>And here is the problem. For example I have 35 files into the directory. When I do this </p>
  
  <pre><code>dataList = dataList.subList(5, 15);
  </code></pre>
  
  <p>It works fine. But when I do this:</p>
  
  <pre><code>dataList = dataList.subList(30, 38);
  </code></pre>
  
  <p>I get error wrong index because I want to get index outside of the List. How I can for example return List elements from 30 to 35? I want if I want to get index from 30 to 40 but if there only 35 indexes to get only 5.</p>