Java List Concatenate listToConcatenatedString(List stringList, String delimiter)

Here you can find the source of listToConcatenatedString(List stringList, String delimiter)

Description

list To Concatenated String

License

Open Source License

Declaration

public static String listToConcatenatedString(List<String> stringList, String delimiter) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 *                       I N T E L   C O R P O R A T I O N
 *   //ww w  . j  av  a2  s . co m
 *  Functional Group: Fabric Viewer Application
 *
 *  File Name: PortUtils.java
 *
 *  Archive Source: $Source$
 *
 *  Archive Log:    $Log$
 *  Archive Log:    Revision 1.9  2015/08/17 18:48:51  jijunwan
 *  Archive Log:    PR 129983 - Need to change file header's copyright text to BSD license txt
 *  Archive Log:    - change backend files' headers
 *  Archive Log:
 *  Archive Log:    Revision 1.8  2015/08/10 17:04:43  robertja
 *  Archive Log:    PR128974 - Email notification functionality.
 *  Archive Log:
 *  Archive Log:    Revision 1.7  2015/07/02 14:24:20  jijunwan
 *  Archive Log:    PR 129442 - login failed with FileNotFoundException
 *  Archive Log:    - fixed a typo in the utility method
 *  Archive Log:
 *  Archive Log:    Revision 1.6  2015/07/01 21:59:24  jijunwan
 *  Archive Log:    PR 129442 - login failed with FileNotFoundException
 *  Archive Log:    - Introduced a Utility method to create JSch that will
 *  Archive Log:    1) check whether known_hosts exist
 *  Archive Log:    2) if not exist, create a new file
 *  Archive Log:    3) if have valid known_hosts file, set it to Jsch. Oterwise, let Jsch maintain it's own memory based temporary file
 *  Archive Log:
 *  Archive Log:    Revision 1.5  2015/05/29 20:33:35  fernande
 *  Archive Log:    PR 128897 - STLAdapter worker thread is in a continuous loop, even when there are no requests to service. Second wave of changes: the application can be switched between the old adapter and the new; moved out several initialization pieces out of objects constructor to allow subnet initialization with a UI in place; improved generics definitions for FV commands.
 *  Archive Log:
 *  Archive Log:    Revision 1.4  2015/03/16 21:56:30  jijunwan
 *  Archive Log:    fixed typo
 *  Archive Log:
 *  Archive Log:    Revision 1.3  2015/03/05 17:30:40  jijunwan
 *  Archive Log:    init version to support Application management
 *  Archive Log:    1) read/write opafm.xml from/to host with backup file support
 *  Archive Log:    2) Application parser
 *  Archive Log:    3) Add/remove and update Application
 *  Archive Log:    4) unique name, reference conflication check
 *  Archive Log:
 *  Archive Log:    Revision 1.2  2015/01/28 23:15:20  jijunwan
 *  Archive Log:    added helpers to support unsigned byte, short and int
 *  Archive Log:
 *  Archive Log:    Revision 1.1  2015/01/11 23:09:30  jijunwan
 *  Archive Log:    renamed PortUtils to Utils
 *  Archive Log:    moved convertFromUnixTime to Utils
 *  Archive Log:
 *  Archive Log:    Revision 1.2  2015/01/11 20:47:22  jijunwan
 *  Archive Log:    updated to the latest FM as of 01/05/2015.
 *  Archive Log:    adapt to changes introduced on FM side.
 *  Archive Log:
 *  Archive Log:    Revision 1.1  2014/10/21 22:14:14  jijunwan
 *  Archive Log:    Added utilities that is able to detect port status. We should always reuse these utilities when possible to ensure we have consistent results
 *  Archive Log:
 *
 *  Overview: 
 *
 *  @author: jijunwan
 *
 ******************************************************************************/

import java.util.List;

public class Main {
    public static String listToConcatenatedString(List<String> stringList, String delimiter) {
        StringBuffer sb = new StringBuffer();
        for (String str : stringList) {
            if (str.contains(delimiter)) {
                throw new IllegalArgumentException(
                        "Source name '" + str + "' contains DELIMITER '" + delimiter + "'");
            }

            if (sb.length() == 0) {
                sb.append(str);
            } else {
                sb.append(delimiter + str);
            }
        }
        return sb.toString();
    }
}

Related

  1. concatWithSeparator(List missingParameters, String separator)
  2. getConcatenatedStringFromList(List input, String delimiter)
  3. getConcatenateString(List codes)
  4. getConcatinatedRange(List numbers)
  5. getZipAndConcatenated(List input1, List input2, String delimiter)
  6. toString(List _toString, String _concator)