Here you can find the source of join(ArrayList
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> |
public static String join(ArrayList<String> nameList, String delimiter)
//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(); } }