Pagination for Users/Groups

Hi there, I am using Okta SDK for java GitHub - okta/okta-sdk-java and I want to build page pagination on the UI.

According to the documentation the pagination is handled automatically and looks like under the hood it uses a custom page iterator, which will request the next page by checking the Link header (from the response)

However, how do we need to handle a case when we need to jump to 5 or any page after the first one? because according to my assumption under the hood we will always start from the 1 page and on the backend side we need to skip redundant elements, Am I right?

The code in this case will be something like this:
final int PAGE_LIMIT = 20;
final int PAGE_NUMBER = 5;

final int SKIP_ELEMENTS = PAGE_LIMIT * PAGE_NUMBER;

final List<Group> groupList = client.getDataStore()
     .getResource("/api/v1/groups?limit=" + PAGE_LIMIT, GroupList.class)
    .stream()
    .skip(SKIP_ELEMENTS)
    .limit(PAGE_LIMIT)
    .collect(Collectors.toList());

If my assumption correct, from the performance side it doesn’t look very effective and all redundant elements will be in application memory and redundant elements will be obtained every time for each iteration since the second page.

I’ll be very appreciative of your comments, thanks in advance

@Andrii looks like you were able to get support from our Java SDK engineers here Pagination for Users/Groups · Issue #562 · okta/okta-sdk-java · GitHub. I’ll go ahead and close your post here.