Java Utililty Methods Collection Element Get

List of utility methods to do Collection Element Get

Description

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

Method

ListgetAll(Map map, Collection indices)
Get all values corresponding to the indices (if they exist in the map).
List<V> result = new ArrayList<>();
for (T i : indices)
    if (map.containsKey(i)) {
        result.add(map.get(i));
return result;
SetgetAllDoubleValues( Map>> doubleCollectionWithValuesToFetch)
This method looks up all the values (for instance years) to display in the, selection box for search parameters when the FNumber box is selected.
Set<Double> returnValues = new TreeSet<Double>();
for (String javaPegId : doubleCollectionWithValuesToFetch.keySet()) {
    returnValues.addAll(doubleCollectionWithValuesToFetch.get(javaPegId).keySet());
return returnValues;
StringgetAllTopicsAsString(final Collection topics)
get All Topics As String
final StringBuffer messages = new StringBuffer();
for (final String topic : topics) {
    messages.append(topic);
    messages.append(System.lineSeparator());
return messages.toString();
Set>getAncestors(Collection> classes)
Returns all the common ancestor classes from the given set of classes.
Set<Class<?>> intersection = new LinkedHashSet<Class<?>>();
for (Class<?> klass : classes) {
    if (intersection.size() == 0) {
        intersection.addAll(getAncestors(klass));
    } else {
        intersection.retainAll(getAncestors(klass));
return intersection;
TgetAnElement(Collection coll)
Returns an arbitrary element from the collection
if (coll == null) {
    throw new IllegalArgumentException("Called with null collection");
} else if (coll.size() == 0) {
    return null;
if (coll instanceof List) {
    return ((List<T>) coll).get(0);
Iterator<T> it = coll.iterator();
return it.next();
TgetAny(final Collection collection)
Returns an arbitrary element from the given collection.
final Iterator<T> iterator = collection.iterator();
if (iterator.hasNext()) {
    return iterator.next();
return null;
TgetAnyFrom(Collection collection)
Gets one element from the provided Collection.
final Iterator<T> iterator = collection.iterator();
if (iterator.hasNext()) {
    return iterator.next();
throw new NoSuchElementException("No value present");
TgetArbitraryMember(Collection s)
get Arbitrary Member
return s.isEmpty() ? null : s.iterator().next();
String[]getArray(Collection dnaCol)
get Array
return (String[]) dnaCol.toArray(new String[0]);
String[]getArrayFromCollection(Collection collection)
get Array From Collection
int size = collection.size();
Object[] objs = collection.toArray();
String[] result = new String[size];
for (int i = 0; i < size; i++) {
    result[i] = objs[i].toString();
return result;