Here you can find the source of join(final char _separator, final boolean _quotes, final Collection
Parameter | Description |
---|---|
_separator | separator between two list items |
_quotes | surround the elements of the string with quotes |
_list | list of strings |
_emptyString | string which is written if the list is empty (or <code>null</code> if no string for empty list is written) |
public static String join(final char _separator, final boolean _quotes, final Collection<String> _list, final String _emptyString)
//package com.java2s; /*//from www .j av a 2 s. co m * Copyright 2008-2011 The MxUpdate Team * * 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. * * Revision: $Rev$ * Last Changed: $Date$ * Last Changed By: $Author$ */ import java.util.Collection; public class Main { /** * A list of string is joined to one string. Between two string the given * separator is set. If quotes parameter is defined each element of the * list is surrounded with quotes. * * @param _separator separator between two list items * @param _quotes surround the elements of the string with quotes * @param _list list of strings * @param _emptyString string which is written if the list is empty (or * <code>null</code> if no string for empty list is * written) * @return joined string of the list items */ public static String join(final char _separator, final boolean _quotes, final Collection<String> _list, final String _emptyString) { final StringBuilder ret = new StringBuilder(); boolean first = true; if (_list.isEmpty()) { if (_emptyString != null) { ret.append(_emptyString); } } else { for (final String elem : _list) { if (!first) { ret.append(_separator); } else { first = false; } if (_quotes) { ret.append('\"'); } ret.append(elem); if (_quotes) { ret.append('\"'); } } } return ret.toString(); } }