get Sub List from index to index - Android java.util

Android examples for java.util:List Sub List

Description

get Sub List from index to index

Demo Code


//package com.java2s;

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

public class Main {
    public static List getSubList(List list, int fromIndex, int toIndex) {
        if (fromIndex > toIndex) {
            return null;
        }//from  w w  w  .j av a  2  s .c  o m

        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