---
title: "Thinking in Java 2: Arrays.toString vs. Arrays.deepToString"
author: "prevention"
date: "2012-10-14T01:45:00Z"
tags: []
slug: "thinking-in-java-2-arrays-tostring-vs-arrays-deeptostring"
draft: false
lastmod: "2014-02-03T16:56:45Z"
id: 2010943
url: "https://prevention.iteye.com/blog/2010943"
---

In *Thinking in Java 1: Returning an array,* I use a low-efficient method to print out an array. Now I wanna introduce you an easy way to show an array, even a multidimensional array.

```
import java.util.Arrays;

public class Test {
	public static void main(String[] args) {
		int[][] a = {{1,2,3}, {4,5,6}};
		String[] b = {"abc", "def"};
		System.out.println(Arrays.deepToString(b));
		System.out.println(Arrays.deepToString(a));
	}
}
```

Results:

```
[abc, def]
[[1, 2, 3], [4, 5, 6]]
```

This example uses the Java SE5 Arrays.deepToString() method, which turns multidimentional arrays into Strings, as you can see from the output.