Java List Join join(List list)

Here you can find the source of join(List list)

Description

join

License

Open Source License

Declaration

public static String join(List<? extends Object> list) 

Method Source Code

//package com.java2s;
/**/*from   w w  w  . j  a  v a 2 s .c o  m*/
 * Copyright (c) 2012 Baozun All Rights Reserved.
 *
 * This software is the confidential and proprietary information of Baozun.
 * 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 Baozun.
 *
 * BAOZUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 * PURPOSE, OR NON-INFRINGEMENT. BAOZUN SHALL NOT BE LIABLE FOR ANY DAMAGES
 * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
 * THIS SOFTWARE OR ITS DERIVATIVES.
 *
 */

import java.util.List;

public class Main {
    public static final String DELIM = ",";

    public static String join(List<? extends Object> list) {
        return join(list, DELIM);
    }

    public static String join(Object[] arr) {
        return join(arr, DELIM);
    }

    public static String join(List<? extends Object> list, String seperator) {
        if (list == null || list.size() == 0)
            return "";
        Object[] t = new Object[0];
        return join(list.toArray(t), seperator);
    }

    public static String join(Object[] arr, String seperator) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < arr.length; i++) {
            sb.append(seperator + arr[i]);
        }
        if (sb.length() > 0)
            sb.deleteCharAt(0);
        return sb.toString();
    }
}

Related

  1. join(List items, CharSequence delimiter)
  2. join(List s, String delimiter)
  3. join(List s, String delimiter)
  4. join(List items, String conjunction)
  5. join(List items, String separator)
  6. join(List olist, String glue)
  7. join(List valueList, String separator)
  8. join(List words, String iDelimiter)
  9. join(List list, T element)