Java List Join join(final List data, String separator)

Here you can find the source of join(final List data, String separator)

Description

Joins elements in a list with separator.

License

Open Source License

Parameter

Parameter Description
data a parameter
separator a parameter

Return

A joined list, joined by the separator.

Declaration

public static String join(final List<String> data, String separator) 

Method Source Code

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

import java.util.List;

public class Main {
    /**//from   w w  w . j  av  a 2 s  . c om
     * Joins elements in a list with separator.
     * 
     * @param data
     * @param separator
     * @return A joined list, joined by the separator.
     */
    public static String join(final List<String> data, String separator) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < data.size(); i++) {
            sb.append(data.get(i));
            // append with separator unless last element
            if (i != data.size() - 1) {
                sb.append(separator);
            }
        }
        return sb.toString();
    }
}

Related

  1. join(final List args)
  2. join(final List list, final String separator)
  3. join(final List things, final String on)
  4. join(final List list, final String delimiter)
  5. join(final List array, final String separator)
  6. join(final List list)
  7. join(final List list, final String sepa)
  8. join(final List path, final char delimiter)
  9. join(final List strings, final String delimiter)

  10. HOME | Copyright © www.java2s.com 2016