提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
将给定的字符串追加到给定的字符串数组,返回由输入数组内容加上给定字符串组成的新数组。
//package com.nowjava; /* n o w j a v a . c o m 提供 */ public class Main { public static void main(String[] argv) throws Exception { String[] array = new String[] { "1", "abc", "level", null, "nowjava.com", "asdf 123" }; String str = "nowjava.com"; System.out.println(java.util.Arrays.toString(addStringToArray( array, str))); } /** * Append the given String to the given String array, returning a new array consisting of the input array * contents plus the given String. * * @param array * the array to append to (can be <code>null</code>) * @param str * the String to append * @return the new array (never <code>null</code>) */ public static String[] addStringToArray(final String[] array, final String str) { /** 来 自 nowjava - 时代Java**/ // if (ObjectUtils.isEmpty(array)) { if (array.length == 0) return new