Java Utililty Methods Collection Merge

List of utility methods to do Collection Merge

Description

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

Method

StringgetMergedString(Collection values, String delimiter)
Get the merged string of the set delimited by a string
Iterator<Integer> iterator = values.iterator();
StringBuffer stringBuffer = new StringBuffer();
while (iterator.hasNext()) {
    Object value = iterator.next();
    stringBuffer.append(value);
    if (iterator.hasNext()) {
        stringBuffer.append(delimiter);
return stringBuffer.toString();
CCmerge(CC target, Collection a, Collection b)
Merge collections a and b into target.
target.addAll(a);
target.addAll(b);
return target;
Collectionmerge(Collection dest, Collection src)
Method merge
if (src == null) {
    return dest;
if (dest == null) {
    return src;
dest.addAll(src);
return dest;
...
Listmerge(Collection splits)
merge
if (splits == null || splits.isEmpty()) {
    return Collections.emptyList();
List<T> list = new ArrayList<>();
for (Collection<T> split : splits) {
    list.addAll(split);
return list;
...
Stringmerge(Collection strings, char separator)
merge
if (strings.isEmpty()) {
    return "";
StringBuilder sb = new StringBuilder();
for (String s : strings) {
    sb.append(s);
    sb.append(separator);
sb.setLength(sb.length() - 1);
return sb.toString();
Listmerge(Collection... collections)
merge
int size = 0;
for (Collection collection : collections) {
    size += collection.size();
ArrayList<T> ret = new ArrayList<T>(size);
for (Collection collection : collections) {
    ret.addAll(collection);
return ret;
Listmerge(Collection... collections)
Merges multiple collections into a list with natural ordering of elements
Set<T> merged = new TreeSet<T>();
for (Collection<T> list : collections) {
    for (T element : list) {
        merged.add(element);
return new ArrayList(merged);
Listmerge(Collection... elems)
Merge few collections in one.
List<T> resultList = arrayList();
if (elems != null) {
    for (Collection<T> eachCollection : elems) {
        resultList.addAll(eachCollection);
return resultList;
Stringmerge(final Collection values)
merge
final StringBuilder merged = new StringBuilder();
boolean first = true;
for (String value : values) {
    if (!first) {
        merged.append(",");
    } else {
        first = false;
    merged.append(value);
return merged.toString();
booleanmerge(J just, Collection justs)
Merges a given justification into a given collection of justifications.
int justSize = just.size();
final Iterator<J> oldJustIter = justs.iterator();
boolean isASubsetOfOld = false;
while (oldJustIter.hasNext()) {
    final J oldJust = oldJustIter.next();
    if (justSize < oldJust.size()) {
        if (oldJust.containsAll(just)) {
            oldJustIter.remove();
...