Java String Array Merge mergeJoin(String sep, String[] a1, String[] a2)

Here you can find the source of mergeJoin(String sep, String[] a1, String[] a2)

Description

merge Join

License

Open Source License

Declaration

public static String mergeJoin(String sep, String[] a1, String[] a2) 

Method Source Code

//package com.java2s;
// License as published by the Free Software Foundation; either

public class Main {
    public static String mergeJoin(String sep, String[] a1, String[] a2) {
        if (a1.length != a2.length) {
            System.out.println("Unable to merge String arrays of different length!");
            return join(a1);
        }/*from  www .j  a  v a 2  s . c  o  m*/

        StringBuilder sb = new StringBuilder(a1[0]);
        sb.append(sep).append(a2[0]);
        for (int i = 1; i < a1.length; i++)
            sb.append(" ").append(a1[i]).append(sep).append(a2[i]);
        return sb.toString();
    }

    public static String join(Object[] array) {
        return join(" ", array);
    }

    public static String join(String sep, Object[] array) {
        StringBuilder sb = new StringBuilder(array[0].toString());
        for (int i = 1; i < array.length; i++)
            sb.append(sep).append(array[i].toString());
        return sb.toString();
    }

    public static String join(String[] array) {
        return join(" ", array);
    }

    public static String join(String sep, String[] array) {
        StringBuilder sb = new StringBuilder(array[0]);
        for (int i = 1; i < array.length; i++)
            sb.append(sep).append(array[i]);
        return sb.toString();
    }

    public static String join(int[] array) {
        return join(" ", array);
    }

    public static String join(String sep, int[] array) {
        StringBuilder sb = new StringBuilder(Integer.toString(array[0]));
        for (int i = 1; i < array.length; i++)
            sb.append(sep).append(array[i]);
        return sb.toString();
    }

    public static String join(double[] array) {
        return join(" ", array);
    }

    public static String join(String sep, double[] array) {
        StringBuilder sb = new StringBuilder(Double.toString(array[0]));
        for (int i = 1; i < array.length; i++)
            sb.append(sep).append(array[i]);
        return sb.toString();
    }
}

Related

  1. merge(String[] src, String delimiter)
  2. merge(String[] str, String sep)
  3. merge(T[] arr0, String delimiter)
  4. mergeInts(int[] values, String delimiter)
  5. mergeJoin(String sep, String[] a1, String[] a2)
  6. mergeString(String currentValue, String newValue)
  7. mergeString(String[] str1, String[] str2)
  8. mergeStrings(Object... strings)
  9. mergeStrings(String s1, String s2)