Java Utililty Methods List Concatenate

List of utility methods to do List Concatenate

Description

The list of methods to do List Concatenate are organized into topic(s).

Method

Listconcat(List l1, List l2)
concat
int size1 = l1.size();
if (size1 == 0) {
    return l2;
int size2 = l2.size();
if (size2 == 0) {
    return l1;
List<T> l3 = new ArrayList<T>(size1 + size2);
l3.addAll(l1);
l3.addAll(l2);
return l3;
Listconcat(List list, T... items)
concat
List<T> ret = new ArrayList<>(list);
for (T item : items) {
    ret.add(item);
return ret;
StringconcatAddresses(List addresses)
concat Addresses
StringBuilder sb = new StringBuilder();
for (String address : addresses) {
    sb.append(address).append(';');
sb.deleteCharAt(sb.length() - 1);
return sb.toString();
T[]concatAll(final T[] empty, Iterable arrayList)
Concatenate an list of arrays of typed-objects
assert (empty.length == 0);
if (arrayList.iterator().hasNext() == false) {
    return empty;
int len = 0;
for (T[] subArray : arrayList) {
    len += subArray.length;
int pos = 0;
T[] result = Arrays.copyOf(empty, len);
for (T[] subArray : arrayList) {
    System.arraycopy(subArray, 0, result, pos, subArray.length);
    pos += subArray.length;
return result;
long[]concatArrays(List arrays, int start, int size)
Concatenate size many values from the passed in arrays, starting at offset start .
long[] result = new long[size];
int howManyLeft = size;
int targetPosition = 0;
int from = start;
for (int i = 0; i < arrays.size() && howManyLeft > 0; i++) {
    long[] current = arrays.get(i);
    int howManyThisRound = Math.min(current.length - from, howManyLeft);
    System.arraycopy(current, from, result, targetPosition, howManyThisRound);
...
ListconcatArraysToList(final T[]... arrays)
concat Arrays To List
List<T> newList = new ArrayList<T>();
for (T[] elArray : arrays) {
    newList.addAll(Arrays.asList(elArray));
return newList;
StringconcatCsvLine(List values, String fieldSeparator)
Basic CSV line concatination with characters escaping
if (values == null || values.isEmpty())
    return null;
StringBuilder builder = new StringBuilder(escapeStringForCsvFormat(values.get(0), fieldSeparator));
for (int i = 1; i < values.size(); i++) {
    builder.append(fieldSeparator);
    builder.append(escapeStringForCsvFormat(values.get(i), fieldSeparator));
return builder.toString();
...
StringconcateAliases(List aliases)
Concatenates all aliases in a String format.
StringBuffer sb = new StringBuffer();
if (aliases.size() > 0) {
    sb.append(aliases.get(0));
    for (int i = 1; i < aliases.size(); i++) {
        sb.append(", "); 
        sb.append(aliases.get(i));
return sb.toString();
ListconcatElementsWithBrackets(List input)
This method concats elements if they contain open brackets so it's not split over multiple elements
List<String> result = new ArrayList<String>();
int openBracketCounter = 0;
String currentElement = null;
for (String el : input) {
    openBracketCounter = openBracketCounter + getAmountOfCharInString('(', el)
            - getAmountOfCharInString(')', el);
    if (currentElement == null) {
        currentElement = el;
...
Stringconcatenate(List aList)
Convenience routine that concatenates the items in the specified list to a String.
StringBuffer buffer = new StringBuffer();
Iterator i = aList.iterator();
if (i.hasNext()) {
    buffer.append(i.next());
    while (i.hasNext()) {
        buffer.append(' ');
        buffer.append(i.next());
return buffer.toString();