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

StringgetCommonSuffix(Collection c)
get Common Suffix
if (c.size() == 0) {
    return "";
Iterator<String> iterator = c.iterator();
String commonSuffix = iterator.next();
while (iterator.hasNext()) {
    commonSuffix = getCommonSuffix(commonSuffix, iterator.next());
return commonSuffix;
StringgetComponentName(Collection existingNames, String name)
Create a unique name for an unnamed component
if (existingNames.contains(name)) {
    int n = 2;
    while (existingNames.contains(name + " (" + n + ")")) {
        n++;
    return name + " (" + n + ")";
} else {
    return name;
...
StringgetDocIdString(Collection docIds)
Decodes the encoded document IDs and returns the comma-separated String of quoted document IDs.
StringBuilder docIdString = new StringBuilder("");
for (String docId : docIds) {
    docIdString.append("'" + docId + "'" + ",");
return docIdString.substring(0, docIdString.length() - 1);
TgetElement(final int index, final Collection coll)
makes sense only if iteration order deterministic!
return getElement(false, index, coll);
ClassgetElementClass(Collection collection)
get Element Class
final E nonNull = firstNonNull(collection);
return nonNull == null ? null : (Class<E>) nonNull.getClass();
TgetElementFromSize1(Collection collection)
get Element From Size
isNotSize1Exception(collection);
return getSingleElement(collection);
doublegetEntropy(Collection values)
get Entropy
if (values.isEmpty()) {
    return -1.0;
double noOfTerms = 0;
for (Double frequency : values) {
    noOfTerms += frequency;
double entropy = 0.0;
...
ListgetEnumNames(Collection values)
Extracts the names of the given enum elements and returns them as string.
final List<String> result = new ArrayList<String>(values.size());
for (final Enum value : values) {
    result.add(value.name());
return result;
StringgetFlatString(Collection elements)
get Flat String
return getFlatString(",", false, elements.toArray());
ObjectgetGivenClassObject(Collection coll, Class clazz)
Get the given class type object from the collection.
for (Iterator iterator = coll.iterator(); iterator.hasNext();) {
    Object object = (Object) iterator.next();
    if (object != null && clazz.isAssignableFrom(object.getClass())) {
        return object;
return null;