Java Utililty Methods List First Item

List of utility methods to do List First Item

Description

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

Method

ListaddFirst(List list, Object values)
add First
list.add(0, values);
return list;
voidaddFirstAndRemoveOldIfNeed(List dest, List src)
add First And Remove Old If Need
if (dest == null) {
    return;
if (src == null || src.isEmpty()) {
    return;
removeDuplicate(dest, src);
dest.addAll(0, src);
...
List

cons(P first, List list)
cons
List<P> builder = new ArrayList<>(list.size() + 1);
builder.add(first);
builder.addAll(list);
return builder;
booleanequalLists(List first, List second)
equal Lists
if (first == null) {
    return second == null;
} else if (second == null) {
    return first == null;
if (first.size() == second.size()) {
    for (int i = 0; i < first.size(); i++) {
        if (!equalObjects(first.get(i), second.get(i))) {
...
voidexpectedOrder(List src, Object first, Object second)
expected Order
int firstIndex = src.indexOf(first);
int secondIndex = src.indexOf(second);
if (firstIndex >= secondIndex) {
    throw new AssertionError("Wrong order for [" + first + ", " + second + "] in " + src);
ListextractFirst(int numberToExtract, List list)
extract First
List<T> topList = new ArrayList<T>();
for (int i = 0; i < numberToExtract && i < list.size(); i++) {
    topList.add(list.get(i));
return topList;
Tfirst(final List list)
Gets the first element of the given list, or null if none.
if (list == null || list.size() == 0)
    return null;
return list.get(0);
Tfirst(final List list, final int oridinal)
Returns the first ordinal element in the list.
final int size = list.size() - 1;
if (size >= oridinal) {
    return list.get(oridinal);
return null;
Tfirst(final List t)
Returns first item in List .
return t != null && !t.isEmpty() ? t.get(0) : null;
Kfirst(List list)
first
if (isNull(list)) {
    return null;
return list.get(0);