Java List Join join(List array, String delim)

Here you can find the source of join(List array, String delim)

Description

Convenience routine to perform a string join for groups in the database.

License

Open Source License

Parameter

Parameter Description
array Array of strings to join together.
delim Delimiter to separate strings with.

Return

Joined string

Declaration

public static String join(List<String> array, String delim) 

Method Source Code

//package com.java2s;
/**/* www  . j ava2  s .  co  m*/
 * $Revision$
 * $Date$
 *
 * Copyright 2006-2010 Daniel Henninger.  All rights reserved.
 *
 * This software is published under the terms of the GNU Public License (GPL),
 * a copy of which is included in this distribution.
 */

import java.util.List;

public class Main {
    /**
     * Convenience routine to perform a string join for groups in the database.
     * @param array Array of strings to join together.
     * @param delim Delimiter to separate strings with.
     * @return Joined string
     */
    public static String join(List<String> array, String delim) {
        StringBuffer sb = join(array, delim, new StringBuffer());
        return sb.toString();
    }

    /**
     * Helper function for primary use join function.
     * @param array Array of strings to join together.
     * @param delim Delimiter to separate strings with.
     * @param sb String buffer instance to work from.
     * @return String buffer instance.
     */
    static StringBuffer join(List<String> array, String delim,
            StringBuffer sb) {
        Boolean first = true;
        for (String s : array) {
            if (!first) {
                sb.append(delim);
            } else {
                first = false;
            }
            sb.append(s);
        }
        return sb;
    }
}

Related

  1. join(List list)
  2. join(List list)
  3. join(List list, String delim)
  4. join(List args, String connector)
  5. join(List args, String seperator)
  6. join(List c, String seperator)
  7. join(List command, List args)
  8. join(List elements)
  9. join(List items, char separator)

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