Monday, August 21, 2006

Break a List into a list of lists

List records contains cells. We break it into lists of size gridCol and store these lists in List grid. (Note in for loop we have a variable n for performance).

int gridCol = 5;
List grid = new ArrayList();
for (int i = 0, n = records.size(); i < n; i += gridCol) {
int toIndex = i + gridCol > n ? n : i + gridCol;
grid.add(records.subList(i, toIndex));
}

0 Comments:

Post a Comment

<< Home