# 1 楼答案 在^{}类中有几个有用的^{}和^{}方法 String[] strings = { "foo", "bar", "waa" }; System.out.println(Arrays.toString(strings)); // [foo, bar, waa] 另一种方法是自己在上面loop,然后分别打印每个项目
# 2 楼答案 使用Apache Commons Lang: org.apache.commons.lang.StringUtils.join(Arrays.asList(strings), ", "); 使用Spring核心: org.springframework.util.StringUtils.collectionToDelimitedString(Arrays.asList(strings), ", ");
# 3 楼答案 您可以使用for循环来完成 下面是一个例子: String[] colors = {"red","blue","black","green","yellow"}; for (String color : colors) { System.out.println(color); } 同时检查:What's the simplest way to print a Java array? 正如Esko在上述链接中所引用的,这是最好的答案: In Java 5 Arrays.toString(arr) or Arrays.deepToString(arr) for arrays within arrays. Note that Object[] version calls .toString() of each object in array. If my memory serves me correct, the output is even decorated in the exact way you're asking.
# 1 楼答案
在^{} 类中有几个有用的^{} 和^{} 方法
另一种方法是自己在上面loop,然后分别打印每个项目
# 2 楼答案
使用Apache Commons Lang:
使用Spring核心:
# 3 楼答案
您可以使用
for
循环来完成下面是一个例子:
同时检查:What's the simplest way to print a Java array?
正如Esko在上述链接中所引用的,这是最好的答案: