Java Utililty Methods List Contain

List of utility methods to do List Contain

Description

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

Method

ObjectgetListValue(Object container, int index)
get List Value
if (container instanceof List) {
    List<?> list = (List<?>) container;
    if (list.size() > index) {
        return list.get(index);
    } else {
        throw new RuntimeException("List has insufficient size, index = " + index);
} else if (container.getClass().isArray()) {
...
booleanidentityContains(Object o, List list)
Check if o is in list with == operator
for (Object l : list) {
    if (o == l)
        return true;
return false;
intindexOfLineContaining(List lines, String s)
index Of Line Containing
s = stripSpaces(s);
for (int i = 0; i < lines.size(); i++) {
    if (stripSpaces(lines.get(i)).contains(s)) {
        return i;
return -1;
booleanisContain(List list, Integer i)
is Contain
return !isCollectionEmpty(list) && i != null && Collections.binarySearch(list, i) >= 0;
booleanisContainedInAll(String keyToSearch, List> list)
is Contained In All
for (Set<String> otherEquivalenceClassesOID : list) {
    if (!otherEquivalenceClassesOID.contains(keyToSearch)) {
        return false;
return true;
booleanisContains(final Object value, final Object... list)
is Contains
return stream(list).anyMatch(it -> Objects.equals(value, it));
booleanisContains(List roles, String role, String module)
is Contains
if (roles.contains(module.toLowerCase() + ":" + role)) {
    return true;
return false;
booleanisEitherContains(List one, List two)
is Either Contains
if (!isAllNotNull(one, two))
    return true;
List<T> longer = one.size() > two.size() ? one : two;
List<T> shorter = one.size() > two.size() ? two : one;
boolean contains = true;
for (T t : shorter) {
    if (!longer.contains(t)) {
        contains = false;
...
booleanisListContainAll(List list, T... checkItems)
is List Contain All
boolean result = true;
if (list.size() > 0 && checkItems.length > 0) {
    for (T t : checkItems) {
        if (!list.contains(t)) {
            result = false;
            break;
} else {
    result = false;
return result;
BooleanisListContainsDuplicateElement(List oneList)
is List Contains Duplicate Element
Boolean containsDuplicateElement = false;
for (Integer i = 0; i < oneList.size() - 1; i++) {
    for (Integer j = i + 1; j < oneList.size(); j++) {
        if (oneList.get(i).equals(oneList.get(j))) {
            return true;
return containsDuplicateElement;