Here you can find the source of concat(List
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 |
public static String concat(List<String> tokens, int start, int end, String joiner)
//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(); } }