Java ArrayList Join join(ArrayList s, String delimiter)

Here you can find the source of join(ArrayList s, String delimiter)

Description

join

License

Open Source License

Declaration

public static String join(ArrayList<String> s, String delimiter) 

Method Source Code

//package com.java2s;
/*//from   w  w  w .j a v a  2 s.  c o m
 * 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:
 * http://www.gnu.org/licenses/gpl.txt
 */

import java.util.ArrayList;

public class Main {
    public static String join(String[] s, String delimiter) {
        StringBuilder buffer = new StringBuilder();
        for (int i = 0; i < s.length; i++) {
            if (i != 0)
                buffer.append(delimiter);
            buffer.append(s[i]);
        }
        return buffer.toString();
    }

    public static String join(ArrayList<String> s, String delimiter) {
        StringBuilder buffer = new StringBuilder();
        for (int i = 0; i < s.size(); i++) {
            if (i != 0)
                buffer.append(delimiter);
            buffer.append(s.get(i));
        }
        return buffer.toString();
    }

    public static String join(ArrayList<String> s, String delimiter, ArrayList<Integer> indices) {
        StringBuilder buffer = new StringBuilder();
        for (int i = 0; i < s.size(); i++) {
            if (i != 0)
                buffer.append(delimiter);
            buffer.append(s.get(indices.get(i)));
        }
        return buffer.toString();
    }
}

Related

  1. join(ArrayList list)
  2. join(ArrayList list, String delimiter)
  3. Join(ArrayList list, String delimiter)
  4. join(ArrayList list, String joinChar)
  5. join(ArrayList nameList, String delimiter)
  6. join(ArrayList strings, String separator)
  7. join(final ArrayList array, final String separator)
  8. join(final ArrayList arry, final String with)
  9. join(final ArrayList parts, final char separator)