Source Code : Concatenates all the passed arrays
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Concatenates all the passed arrays
/*
* Copyright WizTools.org
* Licensed under the Apache License, Version 2.0:
* http://www.apache.org/licenses/LICENSE-2.0
*/
//package org.wiztools.commons;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author subwiz
*/
public final class ArrayUtil {
/**
* Determines if the passed object is of type array.
* @param o The object to determine if it is an array.
* @return true if the passed object is an array.
* @throws NullPointerException when the passed object is null.
*/
public static boolean isArray(Object o) throws NullPointerException {
if(o == null)
throw new NullPointerException("Object is null: cannot determine if it is of array type.");
else {
return o.getClass().isArray();
}
}
/**
* Concatenates all the passed parameters.
* @param <T>
* @param objs
* @return
*/
public static <T> T[] concat(T[] ... objs){
List<T> out = new ArrayList<T>();
int i = 0;
T[] pass = null;
for(T[] o: objs){
for(int j=0; j<o.length; j++){
out.add(o[j]);
i++;
}
pass = o;
}
return out.toArray(pass);
}
// Primitive types for quicker copy:
public static short[] concat(short[] ... objs){
int count = 0;
for(short[] o: objs){
count += o.length;
}
final short[] out = new short[count];
int i = 0;
for(short[] o: objs){
for(int j=0; j<o.length; j++){
out[i] = o[j];
i++;
}
}
return out;
}
public static int[] concat(int[] ... objs){
int count = 0;
for(int[] o: objs){
count += o.length;
}
final int[] out = new int[count];
int i = 0;
for(int[] o: objs){
for(int j=0; j<o.length; j++){
out[i] = o[j];
i++;
}
}
return out;
}
public static long[] concat(long[] ... objs){
int count = 0;
for(long[] o: objs){
count += o.length;
}
final long[] out = new long[count];
int i = 0;
for(long[] o: objs){
for(int j=0; j<o.length; j++){
out[i] = o[j];
i++;
}
}
return out;
}
public static byte[] concat(byte[] ... objs){
int count = 0;
for(byte[] o: objs){
count += o.length;
}
final byte[] out = new byte[count];
int i = 0;
for(byte[] o: objs){
for(int j=0; j<o.length; j++){
out[i] = o[j];
i++;
}
}
return out;
}
public static char[] concat(char[] ... objs){
int count = 0;
for(char[] o: objs){
count += o.length;
}
final char[] out = new char[count];
int i = 0;
for(char[] o: objs){
for(int j=0; j<o.length; j++){
out[i] = o[j];
i++;
}
}
return out;
}
public static float[] concat(float[] ... objs){
int count = 0;
for(float[] o: objs){
count += o.length;
}
final float[] out = new float[count];
int i = 0;
for(float[] o: objs){
for(int j=0; j<o.length; j++){
out[i] = o[j];
i++;
}
}
return out;
}
public static double[] concat(double[] ... objs){
int count = 0;
for(double[] o: objs){
count += o.length;
}
final double[] out = new double[count];
int i = 0;
for(double[] o: objs){
for(int j=0; j<o.length; j++){
out[i] = o[j];
i++;
}
}
return out;
}
public static boolean[] concat(boolean[] ... objs){
int count = 0;
for(boolean[] o: objs){
count += o.length;
}
final boolean[] out = new boolean[count];
int i = 0;
for(boolean[] o: objs){
for(int j=0; j<o.length; j++){
out[i] = o[j];
i++;
}
}
return out;
}
}
Thank with us