Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
kakooo16
Creator
Creator

ArrayList Pagination

Hello ,

I have a little issue to get my second iteration in the list below

0693p000009rKuOAAU.png

 

My list : [1, 2 ,3, 4, 5, 6 , 7 ,8, 9, 10, 11, 12]

Here is my code to get the first 3 items :

int endOf = (context.offset)+3;

ArrayList<String> ids2 = new ArrayList<String>(ids.subList(context.offset, endOf));    

 

System.out.println(ids2) ;

With my initialisation of context.offset = 0 .

*** Here is the result :

[1, 2, 3]

 

Now i would like to get the second iteration :

[4, 5, 6] and the third iteration : [7, 8, 9] and the rest of the iteration until my list is done .

 

 

How to do so ?

Thanks in advance .

1 Solution

Accepted Solutions
cadap
Contributor III
Contributor III

Hi,

 

You can do it like this:

0693p000009rOr4AAE.jpg

Here as text:

//initialize list

List<String> ids = new ArrayList<>();

for (int i=1;i<=12;i++){

   ids.add(String.valueOf(i));

}

 

//inititalize vars

int split_every = 3;

int count = 0;

 

//logic

for (String s: ids){

 count++;

 if (count % split_every == 0){

   List<String> ids2 = new ArrayList<>(ids.subList(count-split_every, count));

    System.out.println(ids2);

 }

}

 

output:

[1, 2, 3]

[4, 5, 6]

[7, 8, 9]

[10, 11, 12]

View solution in original post

1 Reply
cadap
Contributor III
Contributor III

Hi,

 

You can do it like this:

0693p000009rOr4AAE.jpg

Here as text:

//initialize list

List<String> ids = new ArrayList<>();

for (int i=1;i<=12;i++){

   ids.add(String.valueOf(i));

}

 

//inititalize vars

int split_every = 3;

int count = 0;

 

//logic

for (String s: ids){

 count++;

 if (count % split_every == 0){

   List<String> ids2 = new ArrayList<>(ids.subList(count-split_every, count));

    System.out.println(ids2);

 }

}

 

output:

[1, 2, 3]

[4, 5, 6]

[7, 8, 9]

[10, 11, 12]