Java Utililty Methods Collection Combine

List of utility methods to do Collection Combine

Description

The list of methods to do Collection Combine are organized into topic(s).

Method

Listcombine(Collection first, Collection second)
combine
List<T> result = new ArrayList<T>(first.size() + second.size());
result.addAll(first);
result.addAll(second);
return result;
Listcombine(Collection... collections)
combine all lists into one list containing all elements.
List<T> list = new ArrayList<T>();
if (collections != null && collections.length > 0) {
    for (Collection<?> c : collections) {
        for (Object t : c) {
            list.add((T) t);
return list;
Stringcombine(Collection strings)
combine
Iterator<String> iter = strings.iterator();
if (!iter.hasNext()) {
    return "";
String rtrn = iter.next();
while (iter.hasNext()) {
    rtrn += "_" + iter.next();
return rtrn;
Collection>combine(final Collection[] c)
Functions that makes every possible combination of items from an array of collection while respecting the order of the collections.
Collection<List<V>> result = new Vector();
Vector<V> combination = new Vector(c.length);
Iterator<V>[] state = new Iterator[c.length];
for (int i = 0; i < c.length; i++) {
    state[i] = c[i].iterator();
    if (state[i].hasNext())
        combination.add(state[i].next());
    else
...
Stringcombine(String separator, Collection parts)
combine
return join(separator, parts);
Stringcombine(String separator, Collection stringCollection)
Combines a collection of strings into a single string, separated by the given character set
return combineArray(separator, stringCollection.toArray(EMPTY_STRING_ARRAY));
Stringcombine(String separator, Collection objs)
Combine the objects in Collection with the specified separator.
StringBuffer sb = new StringBuffer();
if (objs != null && objs.size() > 0) {
    Iterator<T> it = objs.iterator();
    for (;;) {
        sb.append(it.next().toString());
        if (it.hasNext())
            sb.append(separator);
        else
...
CollectioncombineAndRemoveDuplicates(Collection collection1, Collection collection2)
combine And Remove Duplicates
Collection<T> merged;
try {
    merged = collection1.getClass().newInstance();
} catch (Exception ex) {
    merged = new ArrayList<T>();
merged.addAll(collection1);
merged.addAll(collection2);
...
CollectioncombineCollections(Collection sessionCollection, Collection reqCollection)
combine Collections
Collection<T> result = null;
if (sessionCollection != null && !sessionCollection.isEmpty()) {
    result = new ArrayList<T>();
    result.addAll(sessionCollection);
if (reqCollection != null && !reqCollection.isEmpty()) {
    if (result == null) {
        result = new ArrayList<T>();
...
ListCombineCollections(final Collection... collections)
Used when you have two or more lists of units, etc and you want all the units in one collection.
final List result = new ArrayList();
for (final Collection collection : collections) {
    result.addAll(collection);
return result;