Java List Join join(List objects)

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

Description

Concatenate a list of objects into a single string (using their "toString" method), joining them with a ",".

License

Open Source License

Parameter

Parameter Description
objects A list of objects to concatenate.

Declaration

@SuppressWarnings("rawtypes")
public static String join(List objects) 

Method Source Code

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

import java.util.List;

public class Main {
    /**//from w  w w . ja va 2 s. com
     * Concatenate a list of objects into a single string (using their
     * "toString" method), joining them with a ",".
     * 
     * @param objects
     *            A list of objects to concatenate.
     * @return
     */
    @SuppressWarnings("rawtypes")
    public static String join(List objects) {
        return join(",", objects);
    }

    /**
     * Concatenate a list of objects into a single string (using their
     * "toString" method), joining them with a specified glue string.
     * 
     * @param glue
     *            A string to use to join the objects.
     * @param objects
     *            A list of objects to concatenate.
     * @return
     */
    @SuppressWarnings("rawtypes")
    public static String join(String glue, List objects) {
        StringBuilder sb = new StringBuilder();
        for (Object o : objects) {
            if (sb.length() > 0)
                sb.append(glue);
            sb.append(o.toString());
        }
        return sb.toString();
    }
}

Related

  1. join(List list, String delim)
  2. join(List list, String delimiter)
  3. join(List list, String flag)
  4. join(List list, String separator)
  5. join(List list, String separator)
  6. join(List objects, String joiner)
  7. join(List strings, String delimiter)
  8. join(List vec, String separator)
  9. join(List items, CharSequence delimiter)