Java Array Printing Guide

In Java, to directly output data from an array, you can use the Arrays.toString() method to convert the array to a string, and then use the System.out.println() method to output that string. Here is a simple example code:

import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        int[] numbers = {1, 2, 3, 4, 5};

        // 直接输出数组数据
        System.out.println(Arrays.toString(numbers));
    }
}

In the example above, we created an integer array called numbers, converted it to a string using the Arrays.toString() method, and displayed the array data using the System.out.println() method. Running the code will output [1, 2, 3, 4, 5], showing all elements in the array.

If you wish to customize the output format or handle array data, you can also iterate through the array and output each element individually.

bannerAds