Java Map to String toString(Map m)

Here you can find the source of toString(Map m)

Description

Convert the given map to a string.

License

Open Source License

Parameter

Parameter Description
m Any map to display

Return

A string (multi-line) containing a view of the desired map

Declaration

public static <A, B> String toString(Map<A, B> m) 

Method Source Code

//package com.java2s;
/*/*  w ww  .j  a v a2s . c om*/
This file is part of leafdigital util.
    
util is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
    
util 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 General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with util.  If not, see <http://www.gnu.org/licenses/>.
    
Copyright 2011 Samuel Marshall.
*/

import java.util.*;

public class Main {
    /**
     * Convert the given map to a string.
     * @param m Any map to display
     * @return A string (multi-line) containing a view of the desired map
     */
    public static <A, B> String toString(Map<A, B> m) {
        StringBuffer sb = new StringBuffer();
        sb.append("[\n");
        for (A key : m.keySet()) {
            sb.append("  " + key + " => " + m.get(key) + "\n");
        }
        sb.append("]");
        return sb.toString();
    }
}

Related

  1. toString(Map varnames_to_Terms)
  2. toString(Map attributes)
  3. toString(Map map)
  4. toString(Map map)
  5. toString(Map map)
  6. toString(Map map)
  7. toString(Map map)
  8. toString(Map map)
  9. toString(Map map)