Java List Join join(List array, String separator)

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

Description

join

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
    public static String join(List array, String separator) 

Method Source Code

//package com.java2s;
/**/*from   ww  w . ja  v  a2 s.  c o  m*/
 * Project: SmartCNP
 * 
 * File Created at 2012-8-30
 * $Id$
 * 
 * Copyright 2010 dianping.com.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Dianping Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with dianping.com.
 */

import java.util.List;

public class Main {
    public static final String EMPTY = "";

    @SuppressWarnings("unchecked")
    public static String join(List array, String separator) {
        if (array == null) {
            return null;
        }
        if (separator == null) {
            separator = EMPTY;
        }
        StringBuffer buf = new StringBuffer();

        for (int i = 0; i < array.size(); i++) {
            if (i > 0) {
                buf.append(separator);
            }
            if (array.get(i) != null) {
                buf.append(array.get(i));
            }
        }
        return buf.toString();
    }
}

Related

  1. join(final String with, final List array)
  2. join(Iterable list)
  3. join(Iterable list, String delimiter)
  4. join(List a, List b)
  5. join(List a_quotedArgs)
  6. join(List elements, String joinWith)
  7. join(List elements, String sep)
  8. join(List items, String separator)
  9. join(List l, String sep)