Java List Concatenate concatenate(List components)

Here you can find the source of concatenate(List components)

Description

Join a list of URI fragments into a URI using '/' as a separator.

License

CDDL license

Parameter

Parameter Description
components the list of URI fragments

Return

the resulting URI

Declaration

public static String concatenate(List<String> components) 

Method Source Code

//package com.java2s;
/*/* w  w  w  . j  a  va2 s.com*/
 * The contents of this file are subject to the terms
 * of the Common Development and Distribution License
 * (the "License").  You may not use this file except
 * in compliance with the License.
 * 
 * You can obtain a copy of the license at
 * http://www.opensource.org/licenses/cddl1.php
 * See the License for the specific language governing
 * permissions and limitations under the License.
 */

import java.util.List;

public class Main {
    /**
     * Join a list of URI fragments into a URI using '/' as a separator.
     * @param components the list of URI fragments
     * @return the resulting URI
     */
    public static String concatenate(List<String> components) {
        StringBuffer buf = new StringBuffer();

        for (int i = 0; i < components.size(); i++) {
            if (i > 0 && buf.charAt(buf.length() - 1) != '/' && components.get(i).charAt(0) != '/')
                buf.append('/');
            buf.append(components.get(i));
        }

        return buf.toString();
    }
}

Related

  1. concateAliases(List aliases)
  2. concatElementsWithBrackets(List input)
  3. concatenate(List aList)
  4. concatenate(List> lists)
  5. concatenate(List list1, List list2)
  6. concatenate(List list)
  7. concatenate(List strings)
  8. concatenate(List xs)
  9. concatenate(List a, List b)

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