在Java中,如何將字符串數組寫入輸出控制檯?java
如下示例演示了經過循環將數組的元素寫入輸出控制檯。shell
package com.yiibai; public class ArrayOutput { public static void main(String[] args) { String[] greeting = new String[3]; greeting[0] = "This is the greeting"; greeting[1] = "for all the readers from"; greeting[2] = "Java Source ."; for (int i = 0; i < greeting.length; i++) { System.out.println(greeting[i]); } } }
執行上面示例代碼,獲得如下結果 -數組
This is the greeting For all the readers From Java source .
示例-2yii
如下示例演示了將數組的元素寫入輸出控制檯 -spa
package com.yiibai; import java.util.*; public class ArrayOutput2 { public static void main(String[] args) { String[] arr = new String[] { "http://", "www", "yiibai", ".com" }; System.out.println(Arrays.toString(arr)); } }
執行上面示例代碼,獲得如下結果 -code
[http://, www, yiibai, .com]
嵌套數組示例字符串
如下示例演示了經過循環將數組的元素寫入輸出控制檯。it
package com.yiibai; import java.util.*; public class ArrayOutput3 { public static void main(String[] args) { String[][] deepArr = new String[][] { { "Max", "Min" }, { "Sum", "Avg" } }; System.out.println(Arrays.toString(deepArr)); System.out.println(Arrays.deepToString(deepArr)); } }
執行上面示例代碼,獲得如下結果 -class
[[Ljava.lang.String;@152b6651, [Ljava.lang.String;@544a5ab2] [[Max, Min], [Sum, Avg]]