Java ArrayList Join join(final ArrayList array, final String separator)

Here you can find the source of join(final ArrayList array, final String separator)

Description

join

License

Apache License

Declaration

public static String join(final ArrayList<String> array, final String separator) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;

import java.util.Iterator;

public class Main {

    public static String join(final ArrayList<String> array, final String separator) {
        StringBuffer result = new StringBuffer();
        if (array != null && array.size() > 0) {
            for (String str : array) {
                result.append(str);//from w ww  .  jav  a 2s.  co m
                result.append(separator);
            }
            result.delete(result.length() - 1, result.length());
        }
        return result.toString();
    }

    public static String join(final Iterator<String> iter, final String separator) {
        StringBuffer result = new StringBuffer();
        if (iter != null) {
            while (iter.hasNext()) {
                String key = iter.next();
                result.append(key);
                result.append(separator);
            }
            if (result.length() > 0)
                result.delete(result.length() - 1, result.length());
        }
        return result.toString();
    }
}

Related

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