Java Array Combine combine(int[][] arr, int[] terms)

Here you can find the source of combine(int[][] arr, int[] terms)

Description

Combine elements in a given two level array and an optional second array of terms, combine them all in a single array of terms

License

Open Source License

Parameter

Parameter Description
arr a parameter

Declaration

public static int[] combine(int[][] arr, int[] terms) 

Method Source Code

//package com.java2s;
/**//  w  ww.j  a va  2s. c  o  m
 *  ClusteringWiki - personalized and collaborative clustering of search results
 *  Copyright (C) 2010  Texas State University-San Marcos
 *  
 *  Contact: http://dmlab.cs.txstate.edu
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Combine elements in a given two level array and an optional
     * second array of terms, combine them all in a single array of terms
     * @param arr
     * @return
     */
    public static int[] combine(int[][] arr, int[] terms) {
        int c = 0;
        if (arr != null)
            for (int i = 0; i < arr.length; i++)
                c += arr[i].length;
        if (terms != null)
            c += terms.length;
        int[] r = new int[c];
        c = 0;
        if (arr != null)
            for (int i = 0; i < arr.length; i++)
                for (int j = 0; j < arr[i].length; j++)
                    r[c++] = arr[i][j];
        if (terms != null)
            for (int i = 0; i < terms.length; i++)
                r[c++] = terms[i];
        return r;
    }
}

Related

  1. combine(int size, Object[]... arrays)
  2. combine(Object[] array1, Object[] array2, Object[] combinedArray)
  3. combine(Object[] first, Object[] last)
  4. combine(Object[] objects, String glue)
  5. combineAlpha(float[] partsAlpha, int partsN)