License Lesser General Public License, version 2.1
Lines 36
Permissions
Owner: Stou S.
Viewable by Everyone
Editable by All Siafoo Users
Hide
Know what you're getting – Unlike many sites, all our code is clearly licensed. Join Siafoo Now or Learn More

Deep vs Shallow array printing Atom Feed 0

In Brief An example showing the difference between shallow (default) and deep printing of arrays.
# 's
 1//package com.wickedcooljava.strings;
2
3import java.util.Arrays;
4
5/*
6Example code from Wicked Cool Java (No Starch Press)
7Copyright (C) 2005 Brian D. Eubanks
8
9This library is free software; you can redistribute it and/or
10modify it under the terms of the GNU Lesser General Public
11License as published by the Free Software Foundation; either
12version 2.1 of the License, or (at your option) any later version.
13
14This library is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public
20License along with this library; if not, write to the Free Software
21Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
23Note: The LGPL licence can be found online at http://www.gnu.org
24
25*/
26/**
27 * This class demonstrates deep versus shallow printing of an array in Java 5.
28 */
29public class DeepString9
30{
31
32 public static void main(String[] args)
33 {
34 Object[] multiDimensional = new Object[] {
35 "mercury", new Object[] {},
36 "venus", new Object[] {},
37 "earth", new Object[] { "moon" },
38 "mars", new Object[] { "phobos", "deimos" }
39 };
40
41 System.out.println(multiDimensional);
42 System.out.println(Arrays.toString(multiDimensional));
43 System.out.println(Arrays.deepToString(multiDimensional));
44 }
45}

An example showing the difference between shallow (default) and deep printing of arrays.