提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
用随机数填充字符串数组
//package com.nowjava; public class Main { /** 来 自 n o w j a v a . c o m **/ public static void main(String[] argv) { int numberOfItems = 42; System.out.println(java.util.Arrays .toString(populateStringArray(numberOfItems))); } public static String[] populateStringArray(int numberOfItems) { final String partialWord = "partialArrayParallel"; String[] dummyStringArray = null; if (numberOfItems > 0) { dummyStringArray = new String[numberOfItems]; for (int i = 0; i < numberOfItems; i++) { final double randomNumber = (Math.random() * numberOfItems); final StringBuilder sb = new StringBuilder(partialWord) .append(rando