Here you can find the source of printMap(Map
Parameter | Description |
---|---|
map | the map |
depth | the depth |
@SuppressWarnings("unchecked") public static void printMap(Map<String, Object> map, int depth)
//package com.java2s; /*/*from w w w . j a va 2s .c o m*/ * Copyright 2017 Walmart, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ import java.util.Map; public class Main { /** * Prints the map. * * @param map the map * @param depth the depth */ @SuppressWarnings("unchecked") public static void printMap(Map<String, Object> map, int depth) { String log = "Parent"; if (depth > 0) { log = "Children"; } StringBuilder str = new StringBuilder(); int loop = depth; while (loop > 0) { str.append('\t'); loop--; } for (Map.Entry<String, Object> entry : map.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); System.out.printf("%s %s: key: %s; value:%s: %n", str.toString(), log, key, value == null ? "" : value.getClass()); if (value instanceof Map) { printMap((Map<String, Object>) value, ++depth); } } } }