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

Object[]GetArrayFromCollection(java.util.Collection col)
Get the contents of list as array
if (col == null) {
    return null;
Object[] arr = new Object[col.size()];
System.arraycopy(col.toArray(), 0, arr, 0, col.size());
return arr;
Object[]getArrays(Object parent, Collection collection)
get Arrays
if (collection.isEmpty()) {
    return EMPTY_ELEMENT_ARRAY;
} else {
    return collection.toArray();
StringgetAssociationCollectionObjectName(Collection currentObjectColl, Collection prevObjectColl)
This method is called to obtain name of the object within the collection.
String objectName = "";
if (currentObjectColl != null && !((Collection) currentObjectColl).isEmpty()) {
    objectName = (((Collection) currentObjectColl).iterator().next()).getClass().getName();
} else if (prevObjectColl != null && !((Collection) prevObjectColl).isEmpty()) {
    objectName = (((Collection) prevObjectColl).iterator().next()).getClass().getName();
return objectName;
StringgetAsString(Collection data, char seperator)
Returns a user specified string representation of a collection
Iterator<?> it = data.iterator();
boolean first = true;
StringBuffer ret = new StringBuffer();
while (it.hasNext()) {
    if (first == false) {
        ret.append(seperator);
    } else {
        first = false;
...
StringgetAsString(Collection input)
get As String
if (input == null || input.isEmpty()) {
    return EMPTY_STRING;
return getUsString(input.toArray(new String[input.size()]));
TgetAt(Collection col, int index)
get At
if (col instanceof List)
    return ((List<T>) col).get(index);
int i;
Iterator<T> it;
for (i = 0, it = col.iterator(); i < index && it.hasNext(); it.next())
    ;
return it.hasNext() ? it.next() : null;
StringgetAuthzNameFromEntityName(String entityName, Collection authzProvidersNames)
get Authz Name From Entity Name
String result = null;
if (entityName != null && entityName.contains("@")) {
    String lastPart = entityName.substring(entityName.lastIndexOf('@') + 1);
    result = authzProvidersNames.contains(lastPart) ? lastPart : null;
return result;
ObjectgetByIndex(Collection availableTransitions, int index)
get By Index
int i = 0;
Iterator<Object> iterator = availableTransitions.iterator();
while (iterator.hasNext()) {
    Object transition = iterator.next();
    if (i == index) {
        return transition;
    } else {
        ++i;
...
TgetByIndex(Collection vals, int idx)
Gets collection value by index.
assert idx < vals.size();
int i = 0;
for (T val : vals) {
    if (idx == i)
        return val;
    i++;
assert false : "Should never be reached.";
...
ListgetByMostFrequent(Collection collection)
Returns a list of unique elements by the most frequent.
if (collection == null || collection.isEmpty()) {
    return null;
final Map<T, Integer> histogram = getHistogram(collection);
List<T> list = new ArrayList<T>();
list.addAll(histogram.keySet());
Collections.sort(list, new Comparator<T>() {
    @Override
...