Concatenate arrays
/*
* LingPipe v. 3.9
* Copyright (C) 2003-2010 Alias-i
*
* This program is licensed under the Alias-i Royalty Free License
* Version 1 WITHOUT ANY WARRANTY, without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Alias-i
* Royalty Free License Version 1 for more details.
*
* You should have received a copy of the Alias-i Royalty Free License
* Version 1 along with this program; if not, visit
* http://alias-i.com/lingpipe/licenses/lingpipe-license-1.txt or contact
* Alias-i, Inc. at 181 North 11th Street, Suite 401, Brooklyn, NY 11211,
* +1 (718) 290-9170.
*/
//package com.aliasi.util;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
* Static utility methods for processing arrays.
*
* @author Bob Carpenter
* @version 4.0.0
* @since LingPipe1.0
*/
public class Arrays {
/**
* Returns the array of characters consisting of the members of
* the first specified array followed by the specified character.
*
* @param cs Characters to start resulting array.
* @param c Last character in resulting array.
* @return Array of characters consisting of the characters in the
* first array followed by the last character.
* @throws NullPointerException If the array of characters is
* null.
*/
public static char[] concatenate(char[] cs, char c) {
char[] result = new char[cs.length+1];
for (int i = 0; i < cs.length; ++i)
result[i] = cs[i];
result[result.length-1] = c;
return result;
}
/**
* Returns a new array of strings containing the elements of the
* first array of strings specified followed by the elements of
* the second array of strings specified.
*
* @param xs First array of strings.
* @param ys Second array of strings.
* @return Concatenation of first array of strings followed by the
* second array of strings.
*/
public static String[] concatenate(String[] xs, String[] ys) {
String[] result = new String[xs.length + ys.length];
System.arraycopy(xs,0,result,0,xs.length);
System.arraycopy(ys,0,result,xs.length,ys.length);
return result;
}
}
Related examples in the same category