Java Utililty Methods List Last Item

List of utility methods to do List Last Item

Description

The list of methods to do List Last Item are organized into topic(s).

Method

ListgetLastXItems(int lastXItems, List list)
get Last X Items
ArrayList<T> sizedList = new ArrayList<T>(list);
if (lastXItems < 0)
    lastXItems = 0;
sizedList.subList(0, Math.max(sizedList.size() - lastXItems, 0)).clear();
return sizedList;
booleanisLast(List list, Object o)
is Last
if (list.get(list.size() - 1).equals(o)) {
    return true;
return false;
booleanisLast(T object, List list)
is Last
if (isEmpty(list))
    return false;
Object last = getLast(list);
return last == null ? object == null : last.equals(object);
booleanisLastIdx(List l, int idx)
is Last Idx
return l.size() == (idx + 1);
booleanisLastIndex(List list, int index)
is Last Index
return index == getLastIndex(list);
booleanisLastIndex(List suggestedList, int i)
is Last Index
return i == suggestedList.size() - 1;
intlastIndexOf(List lines, String... conditions)
last Index Of
for (int i = lines.size() - 1; i >= 0; i--) {
    String line = lines.get(i);
    if (matchLine(line, conditions))
        return i;
return -1;
intlastIndexOfIdentical(List l, T element, int startingAt)
Finds the last location of an element in the List using the == operator for comparison.
for (int i = startingAt; i >= 0; i--) {
    if (l.get(i) == element) {
        return i;
return -1;
StringBufferlistToWorkspaceLocationHistoryString(List lastUsedWorkspaceLocationList)
list To Workspace Location History String
StringBuffer lastUsedWorkspaceLocations = new StringBuffer();
for (String workspaceLocationHistoryEntry : lastUsedWorkspaceLocationList) {
    lastUsedWorkspaceLocations.append(workspaceLocationHistoryEntry);
    lastUsedWorkspaceLocations.append(WORKSPACE_LOCATION_HISTORY_PREFERENCE_SPLIT_CHAR);
return lastUsedWorkspaceLocations;
booleanremoveBySwapLast(List a, Object o)
Removes element from List by swapping with last element.
int idx = a.indexOf(o);
if (idx == -1)
    return false;
removeBySwapLast(a, idx);
return true;