Java tutorial
//package com.java2s; /** * <p> * This class includes utility methods used by mobility actions targeting * Android nodes. * </p> * * <p> * Copyright (c) 2011, Distributed Systems Group, University of Parma, Italy. * Permission is granted to copy, distribute and/or modify this document under * the terms of the GNU Free Documentation License, Version 1.3 or any later * version published by the Free Software Foundation; with no Invariant * Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the * license is included in the section entitled "GNU Free Documentation License". * </p> * * @author Alessandro Grazioli (grazioli@ce.unipr.it) * */ import java.lang.reflect.Array; public class Main { /** * Method to merge two arrays. * * @param firstObject * The first array to be merged * * @param secondObject * The second array to be merged * * @return an object containing the elements of the merged arrays */ private static Object joinArrays(Object firstObject, Object secondObject) { Class<?> o1Type = firstObject.getClass().getComponentType(); Class<?> o2Type = secondObject.getClass().getComponentType(); if (o1Type != o2Type) throw new IllegalArgumentException(); int firstObjectSize = Array.getLength(firstObject); int secondObjectSize = Array.getLength(secondObject); Object array = Array.newInstance(o1Type, firstObjectSize + secondObjectSize); int offset = 0, i; for (i = 0; i < firstObjectSize; i++, offset++) Array.set(array, offset, Array.get(firstObject, i)); for (i = 0; i < secondObjectSize; i++, offset++) Array.set(array, offset, Array.get(secondObject, i)); return array; } }