Java List Contain containsId(List aList, Object anObj)

Here you can find the source of containsId(List aList, Object anObj)

Description

Returns whether list contains identical given object (accepts null list).

License

Open Source License

Declaration

public static boolean containsId(List aList, Object anObj) 

Method Source Code


//package com.java2s;

import java.util.*;

public class Main {
    /**//w w w .j a  va 2 s .c  o m
     * Returns whether list contains identical given object (accepts null list).
     */
    public static boolean containsId(List aList, Object anObj) {
        return indexOfId(aList, anObj) >= 0;
    }

    /**
     * Returns index of identical given object in given list.
     */
    public static int indexOfId(List aList, Object anObj) {
        // Iterate over list objects and return index if identical exists
        for (int i = 0, iMax = size(aList); i < iMax; i++)
            if (anObj == aList.get(i))
                return i;

        // Return -1 if identical doesn't exist
        return -1;
    }

    /**
     * Returns the size of a list (accepts null list).
     */
    public static int size(List aList) {
        return aList == null ? 0 : aList.size();
    }

    /**
     * Returns the object at the given index (returns null object for null list or invalid index).
     */
    public static <T> T get(List<T> aList, int anIndex) {
        return aList == null || anIndex < 0 || anIndex >= aList.size() ? null : aList.get(anIndex);
    }
}

Related

  1. containsExactly(Collection list, T... mustHaveItems)
  2. containsExactly(List items, T... itemsToMatch)
  3. containsExternalFilter(List filterList, String dataSetExtId, String dataSourceExtId)
  4. containsFileName(String fileName, List filterList)
  5. containsHelpRequest(List args)
  6. containsIgnoreCase(final String candidate, final List options)
  7. containsIgnoreCase(final String string, final List list)
  8. containsIgnoreCase(List list, String strIn)
  9. containsIgnoreCase(List list, String findMe)