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

Listconcatenate(List> lists)
Convert the list of lists into a single list
List<T> result = new ArrayList<T>();
for (List<T> list : lists) {
    result.addAll(list);
return result;
Listconcatenate(List list1, List list2)
concatenate
List<Object> returnList = new ArrayList();
if (list1.size() == 0) {
    return list2;
} else if (list2.size() == 0) {
    return list1;
} else if ((list1.size() > 1 && list2.size() > 1 && list1.size() != list2.size())) {
    returnList.add(list1.get(0).toString() + list2.get(0).toString());
} else if (list1.size() == list2.size()) {
...
Stringconcatenate(List components)
Join a list of URI fragments into a URI using '/' as a separator.
StringBuffer buf = new StringBuffer();
for (int i = 0; i < components.size(); i++) {
    if (i > 0 && buf.charAt(buf.length() - 1) != '/' && components.get(i).charAt(0) != '/')
        buf.append('/');
    buf.append(components.get(i));
return buf.toString();
Stringconcatenate(List list)
Concatenates a list of string values.
StringBuilder sb = new StringBuilder();
boolean isFirst = true;
for (String string : list) {
    if (isFirst) {
        isFirst = false;
    } else {
        sb.append(", ");
    sb.append(string);
return sb.toString();
Stringconcatenate(List strings)
Concatenate a list with items separated with a space.
StringBuilder cmdsb = new StringBuilder();
for (String s : strings) {
    cmdsb.append(s);
    cmdsb.append(" ");
return cmdsb.toString();
Stringconcatenate(List xs)
concatenate
StringBuilder sb = new StringBuilder();
xs.forEach(ss -> sb.append(ss));
return sb.toString();
Listconcatenate(List a, List b)
The given lists are not modified.
if (a.isEmpty()) {
    return b;
if (b.isEmpty()) {
    return a;
List<T> l = new ArrayList<>(a.size() + b.size());
l.addAll(a);
...
Stringconcatenate(List contents, String separator)
concatenate
if (contents == null || contents.isEmpty())
    return null;
String concatenation = "";
for (Object content : contents) {
    concatenation += content.toString() + separator;
return concatenation.substring(0, concatenation.length() - separator.length());
Listconcatenate(List... lists)
Concatenates multiple lists into one new list.
if (lists == null)
    return new ArrayList<>();
List<T> result = new ArrayList<>();
for (List<T> l : lists) {
    if (l != null)
        result.addAll(l);
return result;
...
String[]concatenate(String[] selectors, List lessExtends)
concatenate
if (lessExtends != null) {
    int off = selectors.length;
    selectors = Arrays.copyOf(selectors, off + lessExtends.size());
    for (int i = 0; i < lessExtends.size(); i++) {
        selectors[off + i] = lessExtends.get(i);
return selectors;
...