Java List Sub List subList(final List list, final int startIndex, final int endIndex)

Here you can find the source of subList(final List list, final int startIndex, final int endIndex)

Description

sub List

License

Open Source License

Declaration

public static <T> java.util.List<T> subList(final List<T> list, final int startIndex, final int endIndex) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static <T> java.util.List<T> subList(final List<T> list, final int startIndex, final int endIndex) {
        if (null == list || list.isEmpty()) {
            return new ArrayList<T>();
        }//w ww  . j  a va  2s .  c  om
        int size = list.size();
        int min = startIndex;
        int max = endIndex == -1 ? size : size < endIndex ? size : endIndex;
        if (max < min) {
            min = min ^ max;
            max = min ^ max;
            min = min ^ max;
        }
        if (min >= size || min < 0) {
            return new ArrayList<T>();
        }
        return list.subList(min, max);
    }
}

Related

  1. subArray(List listA, List listB)
  2. subList(final Iterable

    parent, final Iterable child)

  3. subList(final List oriList, int[] indexes)
  4. subList(final List list, final int first, final int count)
  5. subList(final List list, final int offset, final int amount)
  6. subList(final List source, final int... indices)
  7. sublist(LinkedHashSet base, int start, int count)
  8. subList(List list, int start, int end)
  9. subList(List list, int fromIndex, int toIndex)