Java String Array Combine combine(String[] a, String[] b, String glue)

Here you can find the source of combine(String[] a, String[] b, String glue)

Description

Combined string elements from two arrays into a single array, gluing together elements of the same index with a delimiter string.

License

BSD License

Parameter

Parameter Description
a First string array.
b Second string array.
glue The delimiter string.

Return

The combined array.

Declaration

public static String[] combine(String[] a, String[] b, String glue) 

Method Source Code

//package com.java2s;
/**//w  w  w .ja va 2 s .  c  o  m
 * @author Charles McGarvey
 * The TopCoder Arena editor plug-in providing support for Vim.
 * 
 * Distributable under the terms and conditions of the 2-clause BSD license;
 * see the file COPYING for a complete text of the license.
 */

public class Main {
    /**
     * Combined string elements from two arrays into a single array, gluing
     * together elements of the same index with a delimiter string.
     * @param a First string array.
     * @param b Second string array.
     * @param glue The delimiter string.
     * @return The combined array.
     */
    public static String[] combine(String[] a, String[] b, String glue) {
        String[] result = new String[Math.min(a.length, b.length)];
        for (int i = 0; i < result.length; ++i) {
            result[i] = a[i] + glue + b[i];
        }
        return result;
    }
}

Related

  1. combine(final String[] left, final String[] right)
  2. combine(String sep, String... s)
  3. combine(String style1, String style2)
  4. combine(String... s)
  5. combine(String... vals)
  6. combine(String[] array1, String[] array2)
  7. combine(String[] strs, String delimeter)
  8. combine(String[] values, String delimiter)
  9. combine(String[] values, String regex)