User Tools

Site Tools


chunked_list_processing

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

chunked_list_processing [2016/03/16 09:56] (current)
mihael created
Line 1: Line 1:
 +====== Chunked List Processing ======
  
 +<sxh java>
 +int blockSize = 3;
 +
 +List<​String>​ values = new ArrayList(Arrays.asList("​one",​ "​two",​ "​three",​ "​four",​ "​five",​ "​six",​ "​seven",​ "​eight",​ "​nine",​ "​ten"​));​
 +
 +while (!values.isEmpty()) {
 +    System.out.println("​Size:​ " + values.size() + " : " + values);
 +    ​
 +    int size = values.size() > blockSize ? blockSize : values.size();​
 +    ​
 +    List<​String>​ subList = values.subList(0,​ size);
 +    System.out.println("​Sublist:​ " + subList);
 +    ​
 +    values.subList(0,​ size).clear();​
 +}
 +</​sxh>​
 +
 +Result:
 +
 +  Size: 10 : [one, two, three, four, five, six, seven, eight, nine, ten]
 +  Sublist: [one, two, three]
 +  Size: 7 : [four, five, six, seven, eight, nine, ten]
 +  Sublist: [four, five, six]
 +  Size: 4 : [seven, eight, nine, ten]
 +  Sublist: [seven, eight, nine]
 +  Size: 1 : [ten]
 +  Sublist: [ten]
 +
 +
 +{{tag>​java}}
chunked_list_processing.txt ยท Last modified: 2016/03/16 09:56 by mihael