Java ArrayList Join Join(ArrayList list, String delimiter)

Here you can find the source of Join(ArrayList list, String delimiter)

Description

This method converts a list of String objects to a single String representation and inserts a delimiter between each object.

License

Open Source License

Parameter

Parameter Description
list List of String objects
delimiter Delimiter

Return

Formatted String representation

Declaration

public static String Join(ArrayList<String> list, String delimiter) 

Method Source Code


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

import java.util.ArrayList;

public class Main {
    /** This method converts a list of String objects to a single String representation and inserts a delimiter between each object.
     * /*from  ww w .j  a  v  a2 s .c o m*/
     * @param list List of String objects
     * @param delimiter Delimiter
     * @return Formatted String representation
     */
    public static String Join(ArrayList<String> list, String delimiter) {
        if (list.isEmpty())
            return "";

        StringBuilder sb = new StringBuilder();

        for (String x : list)
            sb.append(x + delimiter);

        sb.delete(sb.length() - delimiter.length(), sb.length());

        return sb.toString();
    }
}

Related

  1. join(ArrayList list, String delimeter)
  2. join(ArrayList arr, String separator)
  3. Join(ArrayList coll, String delimiter)
  4. join(ArrayList list)
  5. join(ArrayList list, String delimiter)
  6. join(ArrayList list, String joinChar)
  7. join(ArrayList nameList, String delimiter)
  8. join(ArrayList s, String delimiter)