Java StringJoiner Usage convertListToString(String[] stringList)

Here you can find the source of convertListToString(String[] stringList)

Description

Given a string list, gets the text from the list in the following manner: apple, pear, pineapple

License

Open Source License

Declaration

public static String convertListToString(String[] stringList) 

Method Source Code

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

import java.util.StringJoiner;

public class Main {
    /**/*w ww. jav  a  2 s  .  c  o  m*/
     * Given a string list, gets the text from the list in the following manner:
     *      apple, pear, pineapple
     */
    public static String convertListToString(String[] stringList) {
        if (stringList == null || stringList.length == 0) {
            return "";
        }
        StringJoiner stringJoiner = new StringJoiner(", ");
        for (String string : stringList) {
            stringJoiner.add(string);
        }
        return stringJoiner.toString();
    }
}

Related

  1. capitalise(String string)
  2. generateDeleteCommand(int deleteDisplayIndex)
  3. getTraceString(StackTraceElement[] stackTraceElements)
  4. implode(T[] array, String delim)
  5. implodeString(Iterable strings, String delimiter)