Java Collection Merge getMergedString(Collection values, String delimiter)

Here you can find the source of getMergedString(Collection values, String delimiter)

Description

Get the merged string of the set delimited by a string

License

Open Source License

Parameter

Parameter Description
values a parameter
delimiter a parameter

Declaration

public static String getMergedString(Collection values, String delimiter) 

Method Source Code

//package com.java2s;
/**/*from  w  ww  .  j a va2s  . c  om*/
 * Genji Scrum Tool and Issue Tracker
 * Copyright (C) 2015 Steinbeis GmbH & Co. KG Task Management Solutions
    
 * <a href="http://www.trackplus.com">Genji Scrum Tool</a>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Collection;
import java.util.Iterator;

public class Main {
    /**
     * Get the merged string of the set delimited by a string
     * @param values
     * @param delimiter
     * @return
     */
    public static String getMergedString(Collection values, String delimiter) {
        Iterator<Integer> iterator = values.iterator();
        StringBuffer stringBuffer = new StringBuffer();
        while (iterator.hasNext()) {
            Object value = iterator.next();
            stringBuffer.append(value);
            if (iterator.hasNext()) {
                stringBuffer.append(delimiter);
            }
        }
        return stringBuffer.toString();
    }
}

Related

  1. merge(CC target, Collection a, Collection b)
  2. merge(Collection dest, Collection src)
  3. merge(Collection splits)
  4. merge(Collection strings, char separator)