数组合并--Java原生方法

只谈情不闲聊 提交于 2020-01-10 20:33:28

废话不多说,直接上代码(工具类):

public static Object[] combineArray(Object one[], Object two[]) throws BussinessException
{
    Object res[] = null;
    if(one != null && one.length > 0 && (two == null || two.length == 0))
    {
        res = new Object[one.length];
        System.arraycopy(one, 0, res, 0, one.length);
    }
    if((one == null || one.length == 0) && two != null && two.length > 0)
    {
        res = new Object[two.length];
        System.arraycopy(two, 0, res, 0, two.length);
    }
    if(two != null && one != null && two.length > 0 && one.length > 0)
    {
        res = new Object[two.length + one.length];
        System.arraycopy(two, 0, res, 0, two.length);
        System.arraycopy(one, 0, res, two.length, one.length);
    }
    return res;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!