Java Collection Element Get getElementClass(Collection collection)

Here you can find the source of getElementClass(Collection collection)

Description

get Element Class

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
    public static <E> Class<E> getElementClass(Collection<E> collection) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Collection;

public class Main {
    @SuppressWarnings("unchecked")
    public static <E> Class<E> getElementClass(Collection<E> collection) {
        final E nonNull = firstNonNull(collection);
        return nonNull == null ? null : (Class<E>) nonNull.getClass();
    }//w ww  .ja  v  a 2  s  . c  o m

    public static <E> E firstNonNull(Collection<E> collection) {
        return firstNonNull(collection, null);
    }

    public static <E> E firstNonNull(Collection<E> collection, E defaultValue) {
        for (E element : collection) {
            if (element != null) {
                return element;
            }
        }
        return defaultValue;
    }
}

Related

  1. getCommonElements( Collection from, Collection to)
  2. getCommonSuffix(Collection c)
  3. getComponentName(Collection existingNames, String name)
  4. getDocIdString(Collection docIds)
  5. getElement(final int index, final Collection coll)
  6. getElementFromSize1(Collection collection)
  7. getEntropy(Collection values)
  8. getEnumNames( Collection values)
  9. getFlatString(Collection elements)