Open In App

Simplest Method to Print Array in Java

Last Updated : 25 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

An array is a structure containing the element of a similar data type as one unit. In this article, we will learn the simplest method to print an array in Java.

Prerequisites

What is the Simplest Method to Print Array in Java?

Arrays.toString() method is used to print One-dimensional (1D) Array in Java. This can be invoked by importing “java.util.Arrays” class. To print an array using this method just pass the array into the arguments of the function.

Syntax:

Arrays.toString(printing_array)

Below is the implementation of printing Array with Arrays.toString() method:

Java




// Java Program to
import java.util.Arrays;
  
// Main Class
public class PrintingArray {
      // Main function
    public static void main(String[] args) {
        
          // Create a 1-D array with some values
        int[] array = {1, 2, 3, 4, 5};
          
          // Printing the array with method
          System.out.print("Integer Array elements are: ");
        System.out.println(Arrays.toString(array));
  
        // String array Created
        String[] stringArray = {"vivek", "deeksha", "chaudhary"};
            
         // Printing th array with Method.
          System.out.print("String Array elements are: ");
        System.out.println(Arrays.toString(stringArray));
    }
}


Output

Integer Array elements are: [1, 2, 3, 4, 5]
Double Array elements are: [1.13, 2.28, 3.33, 44.4, 54.5]
String Array elements are: [vivek, deeksha, chaudhary]




To know more the topic refer to Java Array article.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads