get Sub List By Count - Android java.util

Android examples for java.util:List Sub List

Description

get Sub List By Count

Demo Code


//package com.java2s;

import java.util.Collection;
import java.util.List;

public class Main {
    public static List getSubListByCount(List list, int fromIndex,
            int length) {
        return getSubList(list, fromIndex, fromIndex + length);
    }/*from w  w  w. jav a 2s  .  c  o  m*/

    public static List getSubList(List list, int fromIndex, int toIndex) {
        if (fromIndex > toIndex) {
            return null;
        }

        int size = size(list);

        if (fromIndex < 0 || toIndex > size) {
            return null;
        }

        return list.subList(fromIndex, toIndex);
    }

    public final static int size(Collection c) {
        return c == null ? 0 : c.size();
    }
}

Related Tutorials