Java ArrayList Join join(ArrayList nameList, String delimiter)

Here you can find the source of join(ArrayList nameList, String delimiter)

Description

Join.

License

Open Source License

Parameter

Parameter Description
nameList <br> <div class="de"> name list</div> <div class="fr"> name list</div> <div class="it"> name list</div>
delimiter <br> <div class="de"> delimiter</div> <div class="fr"> delimiter</div> <div class="it"> delimiter</div>

Return

the string

Declaration

public static String join(ArrayList<String> nameList, String delimiter) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 *
 * The authorship of this code and the accompanying materials is held by medshare GmbH, Switzerland.
 * All rights reserved. http://medshare.net
 *
 * Project Team: https://sourceforge.net/p/ehealthconnector/wiki/Team/
 *
 * This code is are made available under the terms of the Eclipse Public License v1.0.
 *
 * Accompanying materials are made available under the terms of the Creative Commons
 * Attribution-ShareAlike 4.0 License.//from w  w w  .  j a v a 2 s .co  m
 *
 * Year of publication: 2015
 *
 *******************************************************************************/

import java.util.ArrayList;

import java.util.Iterator;

public class Main {
    /**
     * <div class="en">Join.</div> <div class="de"></div> <div class="fr"></div>
     * <div class="it"></div>
     * 
     * @param nameList
     * <br>
     *          <div class="de"> name list</div> <div class="fr"> name list</div>
     *          <div class="it"> name list</div>
     * @param delimiter
     * <br>
     *          <div class="de"> delimiter</div> <div class="fr"> delimiter</div>
     *          <div class="it"> delimiter</div>
     * @return the string
     */
    public static String join(ArrayList<String> nameList, String delimiter) {
        String string;
        StringBuilder builder;

        if (nameList == null || nameList.isEmpty())
            return "";
        Iterator<String> iter = nameList.iterator();
        string = iter.next();
        if (string.equals("")) {
            builder = new StringBuilder(iter.next());
        } else {
            builder = new StringBuilder(iter.next());
        }
        while (iter.hasNext()) {
            string = iter.next();
            if (string.equals("")) {
            } else {
                builder.append(delimiter).append(string);
            }
        }
        return builder.toString();
    }
}

Related

  1. Join(ArrayList coll, String delimiter)
  2. join(ArrayList list)
  3. join(ArrayList list, String delimiter)
  4. Join(ArrayList list, String delimiter)
  5. join(ArrayList list, String joinChar)
  6. join(ArrayList s, String delimiter)
  7. join(ArrayList strings, String separator)
  8. join(final ArrayList array, final String separator)
  9. join(final ArrayList arry, final String with)