toString() – list of array elements

Returns a string representation of the contents of the specified array. The string representation consists of a list of the array’s elements, enclosed in square brackets.

Code Explanation
LineDescription
5Declaration and initialization of the array myArray with the values 1, 2, 3, 4 and 5.
7The toSting() Method returns a string representation of the contents of myArray
import java.util.Arrays;

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

        System.out.println(Arrays.toString(myArray));
    }
}
Output
[1, 2, 3, 4, 5]