Java Array Implode implode(String[] values, String separator, String beforeEach, String afterEach)

Here you can find the source of implode(String[] values, String separator, String beforeEach, String afterEach)

Description

implode

License

Apache License

Declaration

public static String implode(String[] values, String separator, String beforeEach, String afterEach) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.List;

public class Main {
    public static String implode(int[] values, String separator) {
        StringBuffer result = new StringBuffer();
        for (int i = 0; i < values.length; i++) {
            if (i > 0)
                result.append(separator);
            result.append(values[i]);//from www. ja  v a2  s  . com
        }
        return result.toString();
    }

    public static String implode(String[] values, String separator) {
        StringBuffer result = new StringBuffer();
        for (int i = 0; i < values.length; i++) {
            if (i > 0)
                result.append(separator);
            result.append(values[i]);
        }
        return result.toString();
    }

    public static String implode(String[] values, String separator, String beforeEach, String afterEach) {
        StringBuffer result = new StringBuffer();
        for (int i = 0; i < values.length; i++) {
            if (i > 0)
                result.append(separator);
            result.append(beforeEach);
            result.append(values[i]);
            result.append(afterEach);
        }
        return result.toString();
    }

    public static String implode(List<String> a, String separator) {
        return implode(a.toArray(new String[a.size()]), separator);
    }
}

Related

  1. implode(String delim, Object[] objects)
  2. implode(String delim, String[] args)
  3. implode(String[] array, String separator)
  4. implode(String[] data, String glue)
  5. implode(String[] inputArray, String glueString)
  6. implodeArray(Object[] array)
  7. implodeArray(Object[] items, String prefix, String suffix, String delimiter, String lastItemSuffix)
  8. implodeArray(String[] inputArray, String glueString)
  9. implodeArray(String[] inputArray, String glueString, int start)