Here you can find the source of join(List> items, String delimiter)
Parameter | Description |
---|---|
items | the items to include in a delimited string |
delimiter | the delimiter character or string to insert between each item in the list |
public static String join(List<?> items, String delimiter)
//package com.java2s; /*/*from ww w . ja v a 2 s .co m*/ * JetS3t : Java S3 Toolkit * Project hosted at http://bitbucket.org/jmurty/jets3t/ * * Copyright 2006-2010 James Murty * * 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 { /** * Joins a list of items into a delimiter-separated string. Each item * is converted to a string value with the toString() method before being * added to the final delimited list. * * @param items * the items to include in a delimited string * @param delimiter * the delimiter character or string to insert between each item in the list * @return * a delimited string */ public static String join(List<?> items, String delimiter) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < items.size(); i++) { sb.append(items.get(i).toString()); if (i < items.size() - 1) { sb.append(delimiter); } } return sb.toString(); } /** * Joins a list of items into a delimiter-separated string. Each item * is converted to a string value with the toString() method before being * added to the final delimited list. * * @param items * the items to include in a delimited string * @param delimiter * the delimiter character or string to insert between each item in the list * @return * a delimited string */ public static String join(Object[] items, String delimiter) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < items.length; i++) { sb.append(items[i]); if (i < items.length - 1) { sb.append(delimiter); } } return sb.toString(); } /** * Joins a list of <em>int</em>s into a delimiter-separated string. * * @param ints * the ints to include in a delimited string * @param delimiter * the delimiter character or string to insert between each item in the list * @return * a delimited string */ public static String join(int[] ints, String delimiter) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < ints.length; i++) { sb.append(ints[i]); if (i < ints.length - 1) { sb.append(delimiter); } } return sb.toString(); } }