Java ArrayList Join join(ArrayList arr, String separator)

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

Description

join

License

Open Source License

Declaration

public static <H> String join(ArrayList<H> arr, String separator) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

public class Main {
    public static String join(Object[] arr, String separator) {
        if (separator == null) {
            separator = ",";
        }/*from   w  w w.ja va  2s. co m*/
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < arr.length; i++) {
            if (i > 0) {
                sb.append(separator);
            }
            sb.append(arr[i].toString());
        }
        return sb.toString();
    }

    public static <H> String join(ArrayList<H> arr, String separator) {
        if (separator == null) {
            separator = ",";
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < arr.size(); i++) {
            if (i > 0) {
                sb.append(separator);
            }
            sb.append(arr.get(i).toString());
        }
        return sb.toString();
    }
}

Related

  1. join(ArrayList list, String delimeter)
  2. Join(ArrayList coll, String delimiter)
  3. join(ArrayList list)
  4. join(ArrayList list, String delimiter)
  5. Join(ArrayList list, String delimiter)