Java Utililty Methods Collection Search

List of utility methods to do Collection Search

Description

The list of methods to do Collection Search are organized into topic(s).

Method

TgetSingle(Collection configs)
get Single
if (configs.size() == 1) {
    for (T t : configs) {
        return t;
return null;
TgetSingleElement(Collection collection)
get Single Element
isEmptyException(collection);
return collection.iterator().next();
TgetSingleElement(Collection collection)
Returns the single element contained by the input collection
if (collection.size() != 1)
    throw new IndexOutOfBoundsException(
            String.format("Expected collection to contain a single element, but observed %d elements: %s",
                    collection.size(), collection.toString()));
return collection.iterator().next();
TgetSingleItem(Collection values)
get Single Item
assert values.size() == 1;
if (values instanceof List) {
    return ((List<T>) values).get(0);
} else {
    return (T) values.toArray()[0];
RgetSingleValue(Iterable collection)
get Single Value
return getSingleValue(collection, "Single value expected");
booleanhasElements(Collection c)
has Elements
return !isEmpty(c);
booleanhasElements(Collection c)
has Elements
return c != null && !c.isEmpty();
booleanhasElements(Collection collection)
Checks whether the COLLECTION is not NULL and has at least one element.
return (null != collection && collection.size() > 0);
booleanhasElements(Collection t)
has Elements
return (t != null) && (t.size() > 0);
inthashCapacityFor(Collection collection)
hash Capacity For
return (int) Math.ceil(collection.size() / 0.75);