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

Objectget(Collection coll, int index)
get
if (coll instanceof List) {
    return ((List) coll).get(index);
} else {
    int i = 0;
    for (Iterator iter = coll.iterator(); iter.hasNext();) {
        Object object = (Object) iter.next();
        if (i == index) {
            return object;
...
Objectget(Collection p_collection, int p_index)
Returns the element at the specified position in the collection.
if (p_collection == null) {
    return null;
Iterator it = p_collection.iterator();
for (int i = 0; it.hasNext(); i++) {
    if (i == p_index) {
        return it.next();
return null;
Objectget(Collection arr, int idx)
get
if (idx < 0)
    return null;
for (Iterator<?> i = arr.iterator(); i.hasNext(); idx--) {
    Object b = i.next();
    if (idx <= 0)
        return b;
return null;
...
Eget(Collection collection, int index)
get
return (E) collection.toArray()[index];
Tget(Collection p_oCol, T p_oObj)
This method provides a way to obtain an object from a collection, given an equal object (logical equals).
if (p_oObj == null)
    return null;
if (isEmpty(p_oCol))
    return null;
if (p_oCol instanceof List)
    return get(p_oCol, ((List<T>) p_oCol).indexOf(p_oObj));
T oObj = null;
T oTempObj = null;
...
Tget(Collection v, int i)
get
Iterator<T> itr = v.iterator();
for (int k = 0; k < i; k++)
    itr.next();
return itr.next();
Tget(final Collection list, final int pos)
get
int cnt = 0;
for (final Object group : list) {
    if (cnt == pos) {
        return (T) group;
    cnt += 1;
return null;
...
Tget(final Collection collection, final int index)
get
if (collection != null) {
    int i = 0;
    for (final T object : collection) {
        if (i == index) {
            return object;
        } else {
            i++;
return null;
CollectiongetAddedItems(Collection oldValues, Collection newValues)
Find out what elements are added between the oldValues and newValues
if (newValues == null) {
    newValues = Collections.emptySet();
Collection<String> deltaInterest = new HashSet<String>(newValues);
if (oldValues == null) {
    oldValues = Collections.emptySet();
deltaInterest.removeAll(oldValues);
...
CollectiongetAdditions(Collection source, Collection target)
get Additions
List<T> addedElements = new ArrayList<T>();
for (T element : target) {
    if (!source.contains(element)) {
        addedElements.add(element);
return addedElements;