Java Array Join joinString(String delimiter, String[] strings)

Here you can find the source of joinString(String delimiter, String[] strings)

Description

join String

License

Open Source License

Declaration

public static String joinString(String delimiter, String[] strings) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.Arrays;

public class Main {
    public static String joinString(String delimiter, String[] strings) {
        ArrayList<String> list = new ArrayList<String>(Arrays.asList(strings));
        list.removeAll(Arrays.asList("", null));

        int len = list.size();
        if (len == 1) {
            return list.get(0);
        }/*www. j  a  va2 s  .  c  o  m*/

        StringBuilder sb = new StringBuilder();
        --len;
        for (int i = 0; i < len; i++) {
            sb.append(list.get(i));
            sb.append(delimiter);
        }
        sb.append(list.get(len));

        return sb.toString();
    }
}

Related

  1. joinByComma(String[] values)
  2. joinByteArrays(final byte[] array1, byte[] array2)
  3. joinBytesArrays(byte[]... args)
  4. joiner(int[] ints, String split)
  5. joinParetos(double[][] pareto1, double[][] pareto2)
  6. joinString(String[] array)
  7. joinString(String[] str, String delimiter)
  8. joinStringArray(String[] array1, String[] array2)
  9. joinStrings(String[] strings, String separator)