Java Collection Join implode(Collection items, String join)

Here you can find the source of implode(Collection items, String join)

Description

implode

License

Open Source License

Declaration

public static String implode(Collection<String> items, String join) 

Method Source Code


//package com.java2s;
/*//from  ww  w  . j a  v a  2  s  .c  o m
 * Copyright 2013 Nebojsa Cvetkovic. All rights reserved.
 *
 * This file is part of JunglistIRC.
 *
 * JunglistIRC 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.
 *
 * JunglistIRC 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 JunglistIRC.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Collection;

public class Main {
    public static String implode(Collection<String> items, String join) {
        String result = "";
        int i = 0;
        for (String s : items) {
            result += s;
            if (i < items.size() - 1) {
                result += join;
            }
            i++;
        }
        return result;
    }

    public static String implode(String[] items, String join) {
        return implode(items, join, 0, items.length);
    }

    public static String implode(String[] items, String join, int begin, int end) {
        String result = "";
        for (int i = begin; i < end; i++) {
            result += items[i];
            if (i < end - 1) {
                result += join;
            }
        }
        return result;
    }
}

Related

  1. getNeoString(String columnName, String delimiter, Collection input, String join)
  2. internalJoin(String sep, Collection pieces)
  3. isDisjoint(Collection a, Collection b)
  4. join(AbstractCollection s, String delimiter)
  5. join(CharSequence p, Collection collection)

  6. HOME | Copyright © www.java2s.com 2016