เพื่อส่งคืนการแสดงสตริงของเนื้อหาลึกของอาร์เรย์ที่ระบุ -
ตัวอย่าง
import java.util.Arrays;
public class Demo {
public static void main(String[] args) {
Object[] ob = {"One","Two", "Three", "Four"};
System.out.println("Array elements...");
for (Object value : ob) {
System.out.println("Value = " + value);
}
System.out.println("The string representation of array is:");
System.out.println(Arrays.deepToString(ob));
}
} ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
Array elements... Value = One Value = Two Value = Three Value = Four The string representation of array is: [One, Two, Three, Four]
ตัวอย่าง
เรามาดูตัวอย่างอื่นกัน −
import java.util.Arrays;
public class Demo {
public static void main(String[] args) {
int[][] arr = new int[3][3];
arr[0][0] = 10;
arr[0][1] = 20;
arr[0][2] = 30;
arr[1][0] = 40;
arr[1][1] = 50;
arr[1][2] = 75;
arr[2][0] = 100;
arr[2][1] = 150;
arr[2][2] = 200;
System.out.println(Arrays.deepToString(arr));
}
} ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
[[10, 20, 30], [40, 50, 75], [100, 150, 200]]