Here you can find the source of getSubList(Iterator iterator, int startIndex, int numberOfItems)
Parameter | Description |
---|---|
iterator | Iterator |
startIndex | int starting index |
numberOfItems | int number of items to keep in the list |
private static List getSubList(Iterator iterator, int startIndex, int numberOfItems)
//package com.java2s; /**//from w w w. j av a 2 s.c om * Licensed under the Artistic License; you may not use this file * except in compliance with the License. * You may obtain a copy of the License at * * http://displaytag.sourceforge.net/license.html * * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Main { /** * Create a list of objects taken from the given iterator and crop the resulting list according to the startIndex * and numberOfItems parameters. * @param iterator Iterator * @param startIndex int starting index * @param numberOfItems int number of items to keep in the list * @return List with values taken from the given object, cropped according to startIndex and numberOfItems * parameters */ private static List getSubList(Iterator iterator, int startIndex, int numberOfItems) { List croppedList = new ArrayList(numberOfItems); int skippedRecordCount = 0; int copiedRecordCount = 0; while (iterator.hasNext()) { Object object = iterator.next(); if (++skippedRecordCount <= startIndex) { continue; } croppedList.add(object); if ((numberOfItems != 0) && (++copiedRecordCount >= numberOfItems)) { break; } } return croppedList; } }