Java List Sub List subList(List query, int first, int max)

Here you can find the source of subList(List query, int first, int max)

Description

sub List

License

Open Source License

Declaration

public static <T> ArrayList<T> subList(List<T> query, int first, int max) 

Method Source Code

//package com.java2s;
/**/*www.  j av a  2 s  .c  o  m*/
 * Exhibit A - UIRF Open-source Based Public Software License.
 * 
 * The contents of this file are subject to the UIRF Open-source Based Public
 * Software License(the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * openelis.uhl.uiowa.edu
 * 
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 * 
 * The Original Code is OpenELIS code.
 * 
 * The Initial Developer of the Original Code is The University of Iowa.
 * Portions created by The University of Iowa are Copyright 2006-2008. All
 * Rights Reserved.
 * 
 * Contributor(s): ______________________________________.
 * 
 * Alternatively, the contents of this file marked "Separately-Licensed" may be
 * used under the terms of a UIRF Software license ("UIRF Software License"), in
 * which case the provisions of a UIRF Software License are applicable instead
 * of those above.
 */

import java.util.ArrayList;

import java.util.Iterator;
import java.util.List;

public class Main {
    public static <T> ArrayList<T> subList(List<T> query, int first, int max) {
        int to;
        Iterator<T> e;
        ArrayList<T> list;

        if (query == null || query.isEmpty() || first >= query.size())
            return null;

        to = Math.min(first + max, query.size());
        list = new ArrayList<T>(to - first);
        e = query.listIterator(first);
        for (; first < to; first++)
            list.add(e.next());

        return list;
    }

    /**
     * Checks the parameter to see if its null or its length is 0.
     * 
     * @return true if object is empty; otherwise false
     */
    public static boolean isEmpty(Object a) {
        if (a instanceof String)
            return ((String) a).length() == 0;
        return a == null;
    }
}

Related

  1. sublist(List list, int start, int limit)
  2. subList(List list, int start, int max)
  3. subList(List list, int[] indexs)
  4. subList(List origin, int start, int length)
  5. subList(List parentList, int start, int end)
  6. subList(List src, int preBatchCount)
  7. subList(List list, int start, int end)
  8. subListByStartAndEnd( List list, M start, M end)
  9. subListMaxSize(List list, int maxSize)