Java List Join join(List list, String delim)

Here you can find the source of join(List list, String delim)

Description

Returns the concatenation of strings from a list using the delimiter indicated.

License

Open Source License

Parameter

Parameter Description
list the list of strings to concatenate.
delim the delimiter to be inserted between each value.

Return

the string containing the concatenated values.

Declaration

public static String join(List<String> list, String delim) 

Method Source Code

//package com.java2s;
/*/*from   ww  w .  ja va2s  .c  o  m*/
 * Copyright ? WebServices pour l'?ducation, 2014
 *
 * This file is part of ENT Core. ENT Core is a versatile ENT engine based on the JVM.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation (version 3 of the License).
 *
 * For the sake of explanation, any module that communicate over native
 * Web protocols, such as HTTP, with ENT Core is outside the scope of this
 * license and could be license under its own terms. This is merely considered
 * normal use of ENT Core, and does not fall under the heading of "covered work".
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */

import java.util.List;

public class Main {
    /**
     * Returns the concatenation of strings from a list using the
     * delimiter indicated.
     * Example: <code>join ([ "A", "B", "CD"], "/") -> "A / B / CD"</code>
     * 
     * @param list the list of strings to concatenate.
     * @param delim the delimiter to be inserted between each value.
     * 
     * @return the string containing the concatenated values.
     */
    public static String join(List<String> list, String delim) {
        boolean isDelimiter = false;
        final StringBuilder builder = new StringBuilder();
        if (list != null) {
            for (String val : list) {
                if (isDelimiter) {
                    builder.append(delim);
                }
                builder.append(val);
                isDelimiter = true;
            }
        }
        return builder.toString();
    }
}

Related

  1. join(List list)
  2. join(List list)
  3. join(List list)
  4. join(List list, String conjunction)
  5. join(List list, String delim)
  6. join(List list, String delimiter)
  7. join(List list, String delimiter)
  8. join(List list, String delimiter)
  9. join(List list, String sep)