集册 Java实例教程 将项添加到数组

将项添加到数组

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

520
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
将项目添加到数组


//package com.nowjava;
/*N o w J a v a . c o m - 时  代  Java 提 供*/

public class Main {

    public static void main(String[] argv) throws Exception {

        String object = "nowjava.com";

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

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

        System.out.println(java.util.Arrays.toString(addToList(object,

                array)));

    }


    public static String[] addToList(String object, String[] array) {

        String[] ret = new String[array.length + 1];

        for (int i = 0; i < array.
展开阅读全文