Java List Join concat(List tokens, int start, int end, String joiner)

Here you can find the source of concat(List tokens, int start, int end, String joiner)

Description

Joins the tokens from position start to position end, the size is end-start.

License

Apache License

Parameter

Parameter Description
tokens the tokens to join
start the position of the first token to join
end the position after which no token is joined
joiner the character used to join the ngrams

Return

a string representing the concatenation of the tokens

Declaration

public static String concat(List<String> tokens, int start, int end, String joiner) 

Method Source Code

//package com.java2s;
/***********************************************************************************************************************
 *
 * Copyright (C) 2010 by the Stratosphere project (http://stratosphere.eu)
 *
 * 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.List;

public class Main {
    /**//from w  w w .j a  va  2  s.c  o  m
     * Joins the tokens from position start to position end, the size is end-start.
     * Tokens will be joined by the space character
     *
     * @param tokens the tokens to join
     * @param start the position of the first token to join
     * @param end the position after which no token is joined
     * @return a string representing the concatenation of the tokens
     */
    public static String concat(List<String> tokens, int start, int end) {
        String joiner = " ";
        return concat(tokens, start, end, joiner);
    }

    /**
     * Joins the tokens from position start to position end, the size is end-start.
     * Tokens will be joined by the specified character
     *
     * @param tokens the tokens to join
     * @param start the position of the first token to join
     * @param end the position after which no token is joined
     * @param joiner the character used to join the ngrams
     * @return a string representing the concatenation of the tokens
     */
    public static String concat(List<String> tokens, int start, int end, String joiner) {
        StringBuilder sb = new StringBuilder();
        for (int i = start; i < end; i++) {
            if (i > start) {
                sb.append(joiner);
            }
            sb.append(tokens.get(i));
        }
        return sb.toString();
    }
}

Related

  1. concatAndJoin(String sep, List data, String prefix, String suffix)
  2. contains(List joinParams, int joinIndex)
  3. getJoinKeyValues(List tuple, List joinKeyIndices)
  4. join(char separator, List seqs)