Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java convert list to page

// Remember that the list it has to not be already paged by the query

public Page<?> toPage(List<?> list, Pageable pageable) {
        int start = (int) pageable.getOffset();
        int end = Math.min((start + pageable.getPageSize()), list.size());
        if(start > list.size())
            return new PageImpl<>(new ArrayList<>(), pageable, list.size());
        return new PageImpl<>(list.subList(start, end), pageable, list.size());
    }
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #java #convert #list #page
ADD COMMENT
Topic
Name
5+1 =