Java List Last Item getLastXItems(int lastXItems, List list)

Here you can find the source of getLastXItems(int lastXItems, List list)

Description

get Last X Items

License

Apache License

Declaration

public static <T> List<T> getLastXItems(int lastXItems, List<T> list) 

Method Source Code

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

import java.util.ArrayList;

import java.util.Collection;

import java.util.List;

public class Main {
    public static <T> List<T> getLastXItems(int lastXItems, List<T> list) {
        ArrayList<T> sizedList = new ArrayList<T>(list);

        if (lastXItems < 0)
            lastXItems = 0;/*from  w ww.  j  ava  2s. com*/

        sizedList.subList(0, Math.max(sizedList.size() - lastXItems, 0)).clear();
        return sizedList;
    }

    public static int size(Collection<?> col) {
        return col == null ? 0 : col.size();
    }
}

Related

  1. getLastNameIndex(List list)
  2. getLastNonNullIndex(final List list)
  3. getLastOrNull(List l)
  4. getLastOrNull(List list)
  5. getLastSectionDays(List sections)
  6. isLast(List list, Object o)
  7. isLast(T object, List list)
  8. isLastIdx(List l, int idx)
  9. isLastIndex(List list, int index)