Java List Sub List subList(List it, int offset, int limit)

Here you can find the source of subList(List it, int offset, int limit)

Description

sub List

License

LGPL

Declaration

public static <T> List<T> subList(List<T> it, int offset, int limit) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.util.Collections;
import java.util.List;

public class Main {
    public static <T> List<T> subList(List<T> it, int offset, int limit) {
        if (it == null) {
            return it;
        }/*from  w  ww.  j  a va  2  s .  c o m*/
        if (it.size() <= offset) {
            return Collections.emptyList();
        }
        if (limit < 0) {
            limit = it.size();
        }
        if (offset < 0) {
            offset = 0;
        }
        limit = offset + limit > it.size() ? it.size() - offset : limit;
        return (limit == it.size() && offset == 0) ? it : it.subList(offset, offset + limit);
    }
}

Related

  1. subList(List list, int begin, int end)
  2. subList(List lst, Collection indices)
  3. subList(List initial, int threshold)
  4. subList(List input, int startIndex, int count)
  5. subList(List input, int startIndex, int count)
  6. sublist(List l, int fromIndex, int toIndex)
  7. subList(List list, int fromIndex, int toIndex)
  8. subList(List list, int fromIndex, int toIndex)
  9. subList(List list, int size)