Skip to content
Advertisement

How can I use loop here, I want to remove 3 elements from list for every turn

I have a list that has some elements, I need to print the first 3 elements when page num = 1, then next 3 elements when page ==2 likewise

JavaScript

Advertisement

Answer

To access the nth page with a page size of k, you need to get the elements in the range n * k to (n + 1) * k. This is easily done using the subList API:

JavaScript

Because this works with zero-based indices, if you want 1 to represent the first page, you need to substract 1 from the page number before using it to calculate the range bounds of subList.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement