Here you can find the source of join(String[] elementList, String separator)
Parameter | Description |
---|---|
elementList | a list of strings to join |
separator | e.g., ",", " ", etc. |
public static String join(String[] elementList, String separator)
//package com.java2s; /*-------------------------------------------------------------------------- * Copyright 2007 utgenome.org// w w w. j ava2 s . c o m * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *--------------------------------------------------------------------------*/ import java.util.List; public class Main { /** * Join the given element list with the specified separator * * @param elementList * a list of strings to join * @param separator * e.g., ",", " ", etc. * @return the concatination of the strings in the elementList, separated by the separator */ public static String join(String[] elementList, String separator) { StringBuffer b = new StringBuffer(); for (int i = 0; i < elementList.length - 1; i++) { b.append(elementList[i]); b.append(separator); // white space } b.append(elementList[elementList.length - 1]); return b.toString(); } public static String join(List elementList, String separator) { StringBuffer b = new StringBuffer(); for (int i = 0; i < elementList.size() - 1; i++) { b.append(elementList.get(i)); b.append(separator); // white space } b.append(elementList.get(elementList.size() - 1)); return b.toString(); } }