Java Array Join joinTokens(String tokens[], String pad)

Here you can find the source of joinTokens(String tokens[], String pad)

Description

Join the words in the array into a String.

License

Apache License

Parameter

Parameter Description
tokens a parameter
pad a parameter

Declaration

public static String joinTokens(String tokens[], String pad) 

Method Source Code

//package com.java2s;
/*/*  w  w  w.j  a  v  a2s  .c  om*/
   Jaivox version 0.7 March 2014
   Copyright 2010-2014 by Bits and Pixels, Inc.
    
   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.
*/

public class Main {
    /**
     * Join the words in the array into a String. This could be done with some
     * assumptions using java.util.Arrays, but the procedure below is simple enough
     * @param tokens
     * @param pad
     * @return 
     */
    public static String joinTokens(String tokens[], String pad) {
        StringBuffer sb = new StringBuffer();
        int n = tokens.length;
        for (int i = 0; i < n - 1; i++) {
            sb.append(tokens[i]);
            sb.append(pad);
        }
        sb.append(tokens[n - 1]);
        String s = new String(sb);
        return s;
    }
}

Related

  1. joinString(String delimiter, String[] strings)
  2. joinString(String[] array)
  3. joinString(String[] str, String delimiter)
  4. joinStringArray(String[] array1, String[] array2)
  5. joinStrings(String[] strings, String separator)
  6. joinWithPrefixes(String[] prefixes, String name, String sep)
  7. joinWithSpaces(final String[] cmds)
  8. stringJoin(Object[] array, String separator)