I have a scenario.I am getting a resultset and adding the elements into an ArrayList. I am giving the limit in my SQL query to 10. I am getting the data of the 10 elements but my ArrayList size is not limited to 10.It is taking the number of as many elements as there are in the database. In for loop I am using arraylist size.Even though only 10 rows data is fetched the size is taking maximum no.of elements present in the database and the loop is going the size-no-times.What can I do to control the size , so that my loop is limited to the limit I gave in the query.Any help would be helpfull.