Java Arrays.toString(double[] a) method example

In this tutorial, You will learn how to get a string representation the array. Java Arrays.toString(double[] a) method returns a string representation.

Returns a string representation of the contents of the specified array.

syntax

public static String toString(double[] a)

Parameters

a - the array whose string representation to return.

Returns

A string representation.

Java Arrays toString(double[] a) example

  • Initialize the double[] array double[] array = { 2.2, 22.12, 90.2, 12.2, 3.0 };
  • Print the elements of original array in for loop.
  • Arrays.toString(array); It returns a string representation of array, it consists of a list of the array's elements, enclosed in square brackets ("[]").
package com.technicalkeeda;

import java.util.Arrays;

public class App {

    public static void main(String[] args) {
        double[] array = {
            2.2,
            22.12,
            90.2,
            12.2,
            3.0
        };

        System.out.println("The elements of array is :- ");
        for (double number: array) {
            System.out.print(number + " ");
        }

        System.out.println("\nThe string representation of array is :- ");

        System.out.println(Arrays.toString(array));
    }
}

output

The elements of array is :- 
2.2 22.12 90.2 12.2 3.0 

The string representation of array is :- 
[2.2, 22.12, 90.2, 12.2, 3.0]