Java Utililty Methods Array Concatenate

List of utility methods to do Array Concatenate

Description

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

Method

T[]concatenate2Arrays(T[] array1, T... array2)
Concatenates two arrays.
List<T> result = new ArrayList<T>();
result.addAll(Arrays.asList(array1));
result.addAll(Arrays.asList(array2));
return result.toArray(array1);
Object[]concatenateArray(Object[] srcOne, Object[] srcTwo)
Concatenate two arrays.
Object[] result = new Object[srcOne.length + srcTwo.length];
System.arraycopy(srcOne, 0, result, 0, srcOne.length);
System.arraycopy(srcTwo, 0, result, srcOne.length, srcTwo.length);
return result;
T[]concatenateArrays(T[] first, T[]... rest)
concatenate Arrays
int totalLength = first.length;
for (T[] array : rest) {
    totalLength += array.length;
T[] result = Arrays.copyOf(first, totalLength);
int offset = first.length;
for (T[] array : rest) {
    System.arraycopy(array, 0, result, offset, array.length);
...
StringconcatenateStrings(Object[] strings, String glueString)
Concatenates the strings into one big string, putting glueString between each pair.
if (strings.length > 0) {
    StringBuilder sb = new StringBuilder(strings[0].toString());
    for (int i = 1; i < strings.length; ++i)
        sb.append(glueString).append(strings[i].toString());
    return sb.toString();
} else
    return "";
int[]concatIntArrays(final int[] l1, final int[] l2)
concat Int Arrays
if (l1 == null)
    return l2;
if (l2 == null)
    return l1;
final int[] result = Arrays.copyOf(l1, l1.length + l2.length);
System.arraycopy(l2, 0, result, l1.length, l2.length);
return result;
StringconcatStrings(String[] strs, String delimiter)
Concatenates the given array of String s with the given delimiter.
StringBuilder builder = new StringBuilder();
for (int i = 0; i < strs.length; i++) {
    builder.append(strs[i]);
    if (i < strs.length - 1)
        builder.append(delimiter);
return builder.toString();
String[]concatTwoStringArray(String[] first, String[] second)
Merge Two String arrays together into one.
List<String> both = new ArrayList<String>(first.length + second.length);
Collections.addAll(both, first);
Collections.addAll(both, second);
return both.toArray(new String[both.size()]);
String[]concatUniq(String[] part1, String[] part2)
Concat two arrays of Strings, and prevent that duplicate Strings are present in result part2 is appended to part1
ArrayList nlist = new ArrayList();
for (int i = 0; i < part1.length; i++) {
    if (!nlist.contains(part1[i]))
        nlist.add(part1[i]);
for (int i = 0; i < part2.length; i++) {
    if (!nlist.contains(part2[i]))
        nlist.add(part2[i]);
...
String[]concatUnique(String[] a, String[] b)
concat Unique
Set<String> result = new HashSet<>();
result.addAll(Arrays.asList(a));
result.addAll(Arrays.asList(b));
return result.toArray(new String[result.size()]);