Java List Combine combine(final List r, final char sep)

Here you can find the source of combine(final List r, final char sep)

Description

Combine elements from a list using separator.

License

Open Source License

Parameter

Parameter Description
r the elements list
sep the separator

Return

a combined string

Declaration

private static String combine(final List<?> r, final char sep) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2015 LegSem.//from   w  ww  . j a  va  2 s. c  o  m
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     LegSem - initial API and implementation
 ******************************************************************************/

import java.util.List;

public class Main {
    /**
     * Combine elements from a list using separator.
     * 
     * @param r the elements list
     * @param sep the separator
     * @return a combined string
     */
    private static String combine(final List<?> r, final char sep) {
        StringBuilder buf = new StringBuilder(r.get(0).toString());

        for (int i = 1; i < r.size(); i++) {
            buf.append(sep);
            buf.append(r.get(i));
        }

        return buf.toString();
    }
}

Related

  1. combine(final List dataChunks)
  2. combine(final List list, final List list2)
  3. combine(int sign, List exponentBits, List mantissaBits)
  4. combine(List r, char sep)