How to Print Array in Java Program

Print Array in Java

In this example, We will show sample program about, How to print array in Java programming language. The example was tested and shared in the same post.

Example Program

package com.dineshkrish;

import java.util.Arrays;

/**
 * 
 * @author Dinesh Krishnan
 *
 */

public class PrintArray {

	public static void main(String[] args) {

		// byte array
		byte[] byteArray = { 10, 30, 40, 50, 50 };

		System.out.println(byteArray);

		System.out.println(Arrays.toString(byteArray)); // printing

		
		// short array
		short[] shortArray = { 100, 200, 300, 400, 500 };

		System.out.println(shortArray);

		System.out.println(Arrays.toString(shortArray)); // printing

		// int array
		int[] intArray = { 1000, 2000, 3000, 4000, 5000 };

		System.out.println(intArray);

		System.out.println(Arrays.toString(intArray)); // printing

		// long array
		long[] longArray = { 10000, 20000, 30000, 40000, 5000 };

		System.out.println(longArray);

		System.out.println(Arrays.toString(longArray)); // printing

		// boolean array
		boolean[] booleanArray = { true, false, true, false, true };

		System.out.println(booleanArray);

		System.out.println(Arrays.toString(booleanArray)); // printing
		
		// float array
		float[] floatArray = {1, 2, 3, 4, 5};
		
		System.out.println(floatArray);
		
		System.out.println(Arrays.toString(floatArray)); // printing
		
		// double array
		double[] doubleArray = {1, 2, 3, 4, 5};
		
		System.out.println(doubleArray);
		
		System.out.println(Arrays.toString(doubleArray)); // printing

	}

}

Output

[[email protected]
[10, 30, 40, 50, 50]
[[email protected]
[100, 200, 300, 400, 500]
[[email protected]
[1000, 2000, 3000, 4000, 5000]
[[email protected]
[10000, 20000, 30000, 40000, 5000]
[[email protected]
[true, false, true, false, true]
[[email protected]
[1.0, 2.0, 3.0, 4.0, 5.0]
[[email protected]
[1.0, 2.0, 3.0, 4.0, 5.0]

References

1. JavaDoc – Arrays Class

Hello, folks, I am a founder of dineshkrish.com. I love Java and Open source technologies, If you find my tutorials are useful, please consider making donations to these charities.