Joins the arraylist into a single string, combining them with commas. - Java Collection Framework

Java examples for Collection Framework:Array Join

Description

Joins the arraylist into a single string, combining them with commas.

Demo Code


//package com.java2s;
import java.util.ArrayList;

public class Main {
    /**/*  w  w w.  j  av a  2  s .  c om*/
     * Joins the arraylist into a single string, combining them with commas.
     * @param list
     * @return
     */
    public static String join(ArrayList<String> list) {
        String item = "";

        for (int i = 0; i < list.size(); i++) {
            if (i > 0)
                item += ",";

            item += list.get(i);
        }

        return item;
    }
}

Related Tutorials