Java Vector from String getStringFromTokens(Vector vector, String delimiter)

Here you can find the source of getStringFromTokens(Vector vector, String delimiter)

Description

Return a String who contains the strings in the Vector vector separated by delimiter.

License

Apache License

Parameter

Parameter Description
vector list of tokens
delimiter String who delimiters the Strings into <I>str</I>

Return

Composed string

Declaration

public static String getStringFromTokens(Vector vector, String delimiter) 

Method Source Code

//package com.java2s;
/**// w  ww .j av  a 2s . com
 * Copyright (C) 2012 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.*;

public class Main {
    /**
     * Return a String who contains the strings in the Vector <I>vector</I>
     * separated by <I>delimiter</I>.
     *
     * @param vector    list of tokens
     * @param delimiter String who delimiters the Strings into <I>str</I>
     * @return Composed string
     */
    public static String getStringFromTokens(Vector vector, String delimiter) {
        int nelem = vector.size();
        // Initial capacity, at least include the delimiters
        StringBuffer str_ret = new StringBuffer(nelem * delimiter.length());

        for (int i = 0; i < nelem; i++) {
            str_ret.append(vector.elementAt(i));

            // The last delimiter isn't added
            if (i < nelem - 1) {
                str_ret.append(delimiter);
            }
        }
        return str_ret.toString();
    }
}

Related

  1. containSource(Vector sources, String source)
  2. convertStringToVector(String source, String separator)
  3. createNodeValueVector(final String val)
  4. getKeyStringAsVector(String keyString, String separator)
  5. getposString(Vector vect_valores, String valor)
  6. implode(Vector handler, String separator)
  7. implode(Vector strings, char delim)
  8. orderedStringInsert(String key, Vector into)
  9. parseArgumentVector(String argStr)