How i can iterate list to get 10 elements each time in java

ArrayList#subList is a very efficient operation. You can iterate over ranges of size 10:

for (int i = 0; i < dbList.size(); i += 10) {
   List<Long> sub = dbList.subList(i, Math.min(dbList.size(),i+10)));
   ... query ...
}

If you use Eclipse Collections (formerly GS Collections) and change dbList to a MutableList or something similar, you can write:

MutableList<Long> dbList = ...;
RichIterable<RichIterable<Long>> chunks = dbList.chunk(10);

If you can't change the return type of dbList, you can wrap it in a ListAdapter.

RichIterable<RichIterable<Long>> chunks = ListAdapter.adapt(dbList).chunk(10);

Note: I am a committer for Eclipse Collections.

Tags:

Mysql

Java

List