How to Print Arrays in Java

When working with arrays in Java, it is useful to print the array contents on the console or on the log file. This is useful for debugging the application. It is possible to print one dimensional or multi-dimensional arrays using for loops. However a much easier solution is to use the deepToString() static method of Arrays class. The following sample program in Java shows how any type of arrays can be printed using the Arrays class of util package.

import java.util.Arrays;

 * How to print arrays in Java. This works with multi-dimensional arrays as well. 
public class PrintArray {
    public static String[] LANGUAGES = new String[] {
    public static String[][] COUNTRIES = new String[][] {
                     {"India","New Delhi"},
                     {"United States","Washington"},
    public static void main(String[] args) {

Do you have a programming problem that you are unable to solve? Please send us your problem and we will publish the solution on this site within 48 hours! Please email us.

Leave a Reply