Java Map Print printMap(Map mp)

Here you can find the source of printMap(Map mp)

Description

print Map

License

Open Source License

Declaration

public static void printMap(Map<?, ?> mp) 

Method Source Code

//package com.java2s;
/*// ww w  . j  a va 2 s  . c  om
 * Utils.java
 *
 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
 *
 * This file is part of BEAST.
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership and licensing.
 *
 * BEAST is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 *  BEAST is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with BEAST; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA  02110-1301  USA
 */

import java.util.Iterator;

import java.util.Map;
import java.util.Map.Entry;

public class Main {
    public static void printMap(Map<?, ?> mp) {

        Iterator<?> it = mp.entrySet().iterator();
        while (it.hasNext()) {

            Entry<?, ?> pairs = (Entry<?, ?>) it.next();
            Object obj = pairs.getValue();

            if (obj instanceof int[]) {

                int[] seq = (int[]) obj;
                System.out.print(pairs.getKey() + " =");

                for (int i = 0; i < seq.length; ++i) {
                    System.out.print(" " + seq[i]);
                }
                System.out.println();

            } else if (obj instanceof double[]) {

                double[] seq = (double[]) obj;
                System.out.print(pairs.getKey() + " =");

                for (int i = 0; i < seq.length; ++i) {
                    System.out.print(" " + seq[i]);
                }
                System.out.println();

            } else {
                System.out.println(pairs.getKey() + " = " + pairs.getValue());
            } // END: obj class check

        }
    }
}

Related

  1. printMap(final Map msg)
  2. printMap(HashMap map)
  3. printMap(Map map)
  4. printMap(Map mp)
  5. printMap(Map theMap)
  6. printMap(Map map)
  7. printMap(Map map)
  8. printMap(Map map)
  9. printMap(Map map)