Java List to String convertListToString(List dests)

Here you can find the source of convertListToString(List dests)

Description

Converts the List to comma-separated String

License

Open Source License

Parameter

Parameter Description
dests List<String>

Return

The comma-separated String

Declaration

public static String convertListToString(List<String> dests) 

Method Source Code

//package com.java2s;
/*/*from   www .  j a  v a 2s . c om*/
Copyright (C) 2012 Hoiio Pte Ltd (http://www.hoiio.com)
    
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
    
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
    
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/

import java.util.List;

public class Main {
    /**
     * Converts the {@code List} to comma-separated {@code String}
     * @param dests {@code List<String>}
     * @return The comma-separated {@code String}
     */
    public static String convertListToString(List<String> dests) {
        StringBuilder destString = new StringBuilder();
        for (String dest : dests) {
            destString.append(dest + ",");
        }

        // remove the last ","
        destString.deleteCharAt(destString.length() - 1);
        return destString.toString();
    }
}

Related

  1. convertListToString(List list)
  2. convertListToString(List list, String delimiter, char encloser)
  3. convertListToString(List list)
  4. convertListToString(List data)
  5. convertListToString(List list, char delimiter, int estimatedLength)
  6. convertListToString(List itemList, String separator)
  7. convertListToString(List listStr, String separator)
  8. convertListToString(List strings)
  9. convertListToString(List strList)

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