Java Array to String convertToString(String[] values, String separator)

Here you can find the source of convertToString(String[] values, String separator)

Description

Convert to string.

License

Apache License

Parameter

Parameter Description
values the values
separator the separator

Return

the string

Declaration

public static String convertToString(String[] values, String separator) 

Method Source Code

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

import java.util.List;

public class Main {
    /**//from ww w  .  j  ava2  s .  co  m
     * Convert to string.
     *
     * @param values the values
     * @param separator the separator
     * @return the string
     */
    public static String convertToString(String[] values, String separator) {
        StringBuilder converted = new StringBuilder();
        if (values != null) {
            for (String value : values) {
                if (converted.length() > 0) {
                    converted.append(separator);
                }
                converted.append(value);
            }
        }
        return converted.toString();
    }

    /**
     * Convert to string.
     *
     * @param values the values
     * @param separator the separator
     * @return the string
     */
    public static String convertToString(List<String> values, String separator) {
        StringBuilder converted = new StringBuilder();
        if (values != null) {
            for (String value : values) {
                if (converted.length() > 0) {
                    converted.append(separator);
                }
                converted.append(value);
            }
        }
        return converted.toString();
    }
}

Related

  1. convertArrayToString(String[] fields, String delimiter)
  2. convertArrayToString(String[] idArray)
  3. convertArrayToString(String[] strArray)
  4. convertByteToString(byte[] objectGuid)
  5. convertToString(String[] args)
  6. deepToString(Object[] a)
  7. encodedSeptetsToString(byte[] encodedSeptets)
  8. getArrayAsString(double[] vals)
  9. intArrayToString(int[] array, String delim)