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

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

By technicalkeeda, Views 247, Date 20-Feb-2018

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

tags Java

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]

Suggested Posts

Yashwant

Yashwant

Hi there! I am founder of technicalkeeda.com and programming enthusiast. My skills includes Java,J2EE, Spring Framework, Nodejs, PHP and lot more. If you have any idea that you would want me to develop? Lets connect: yashwantchavan[at][gmail.com]