Java Collection Element Get getGivenClassObject(Collection coll, Class clazz)

Here you can find the source of getGivenClassObject(Collection coll, Class clazz)

Description

Get the given class type object from the collection.

License

Apache License

Parameter

Parameter Description
coll a parameter
clazz a parameter

Declaration

public static final Object getGivenClassObject(Collection coll, Class clazz) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Collection;

import java.util.Iterator;

public class Main {
    /**//from   w w w .j  a  v  a 2s  .com
     * Get the given class type object from the collection. Return null if not found.
     * @param coll
     * @param clazz
     * @return
     */
    public static final Object getGivenClassObject(Collection coll, Class clazz) {
        for (Iterator iterator = coll.iterator(); iterator.hasNext();) {
            Object object = (Object) iterator.next();
            if (object != null && clazz.isAssignableFrom(object.getClass())) {
                return object;
            }
        }
        return null;
    }
}

Related

  1. getElementClass(Collection collection)
  2. getElementFromSize1(Collection collection)
  3. getEntropy(Collection values)
  4. getEnumNames( Collection values)
  5. getFlatString(Collection elements)
  6. getHighest(final Collection elements, final Comparator c)
  7. getImplement(Class aClass, Collection> classCollection)
  8. getIndex(Object collectionOrArray, int index)
  9. getIndexedValue(Object collection, int index)