提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
填充数组
// 来自 N o w J a v a . c o m //package com.nowjava; import java.util.Arrays; public class Main { public static void main(String[] argv) throws Exception { String value = "nowjava.com"; int length = 2; System.out.println(java.util.Arrays.toString(fillArray(value, length))); } public static String[] fillArray(String value, int length) { String[] result = new String[length]; /** from n o w j a v a . c o m - 时代Java**/ Arrays.fill(result, value); return result; } public static int[] fillArray(int value, int length) { int[] result = new int[length]; Arrays.fill(result, value); return result; } public static String toString(Object[] array) { StringBuffer sb = new StringBuffer(); sb.append("["); for (int i =