How to Print an Array in Java


In this example we will show a few ways to print an array in Java.

Source Code

package com.beginner.examples;

import java.util.Arrays;

public class PrintArrayExamples {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String[] strs={"A","B","C","D"};
		int [] nums={2,6,9,10};
		int [][] deepNums={{2,5,6},{7,8,0}};
		System.out.println(Arrays.toString(strs));
		System.out.println(Arrays.toString(nums));
		System.out.println(Arrays.deepToString(deepNums));
		
		
	}
	
		
}

Output:

[A, B, C, D]
[2, 6, 9, 10]
[[2, 5, 6], [7, 8, 0]]

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments