Concatenate arrays : Auto Growth Array « Collections Data Structure « Java






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

1.Growable int[]
2.Your own auto-growth Array
3.Long Vector
4.Int Vector (from java-objects-database)
5.ArrayList of int primitives
6.ArrayList of long primitives
7.ArrayList of short primitives
8.ArrayList of double primitives
9.ArrayList of boolean primitives
10.ArrayList of char primitives
11.ArrayList of byte primitives
12.Growable String array with type specific access methods.
13.Auto Size Array
14.Dynamic Int Array
15.Dynamic Long Array
16.Int Array
17.Int Array List
18.ArrayList of float primitives
19.Fast Array
20.Extensible vector of bytes
21.Int Vector
22.A two dimensional Vector
23.Lazy List creation based on ArrayList
24.Append the given Object to the given array
25.Adds all the elements of the given arrays into a new array.
26.Simple object pool
27.A variable length Double Array: expanding and contracting its internal storage array as elements are added and removed.
28.Append item to array
29.A growable array of bytes
30.Doubles the size of an array
31.Adds the object to the array.
32.Double List