集册 Java实例教程 合并两个对象数组

合并两个对象数组

欢马劈雪     最近更新时间:2020-01-02 10:19:05

490
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
合并两个对象数组


//package com.book2s;/**n o w j a   v  a . c o m - 时  代  Java**/


public class Main {

    public static void main(String[] argv) {

        Object[] pa = new String[] { "1", "abc", "level", null,

                "book2s.com", "asdf 123" };

        Object[] pb = new String[] { "1", "abc", "level", null,

                "book2s.com", "asdf 123" };

        System.out.println(java.util.Arrays.toString(mergeTwoObjectArrays(

                pa, pb)));

    }


    public static Object[] mergeTwoObjectArrays(Object[] pa, Object[] pb) {
    /*
    NowJava.com - 时  代  Java 提供
    */


        if (pa == null)

            return pb;


        if (pb == null)

            return pa;


        Object[] arr = new Object[pa.length + pb.length];

        for (int x 
展开阅读全文