Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java paging util

Tags:

java

I have List of Object. I need to do pagination.
The input parameters are the maximum number object per Page and Page number.

For example input list = ("a", "b", "c", "d", "e", "f")
The maximum number per Page is 2 Page number is 2 Result = ("c", "d")

Are there any ready-made classes(libs) to do this? For example Apache project or so on.

like image 343
Alstresh Avatar asked Aug 31 '12 11:08

Alstresh


1 Answers

int sizePerPage=2;
int page=2;

int from = Math.max(0,page*sizePerPage);
int to = Math.min(list.size(),(page+1)*sizePerPage)

list.subList(from,to)
like image 56
Christian Kuetbach Avatar answered Oct 13 '22 06:10

Christian Kuetbach