Here you can find the source of join(List
Parameter | Description |
---|---|
strings | the list of elements |
delimiter | the delimiter |
public static String join(List<String> strings, String delimiter)
//package com.java2s; /* /*from w w w .j a v a2 s . c o m*/ * Copyright 2010 University of Southern California * * 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; import java.util.Set; public class Main { /** * Join the elements of the set * * @param strings * the list of elements * @param delimiter * the delimiter * @return the join string of the set elements */ public static String join(List<String> strings, String delimiter) { if (strings == null || delimiter == null) { return ""; } StringBuffer buf = new StringBuffer(); boolean first = true; for (String value : strings) { if (first) { first = false; } else { buf.append(delimiter); } buf.append(value); } return buf.toString(); } /** * Join the elements of the set * * @param strings * the set of elements * @param delimiter * the delimiter * @return the join string of the set elements */ public static String join(Set<String> strings, String delimiter) { if (strings == null || delimiter == null) { return ""; } StringBuffer buf = new StringBuffer(); boolean first = true; for (String value : strings) { if (first) { first = false; } else { buf.append(delimiter); } buf.append(value); } return buf.toString(); } }