Java HashMap Convert hashMapToString(HashMap map)

Here you can find the source of hashMapToString(HashMap map)

Description

Create a string representation of hash map as key="value" key="value" ...

License

Open Source License

Parameter

Parameter Description
map a parameter

Declaration

public static String hashMapToString(HashMap<String, ?> map) 

Method Source Code

//package com.java2s;
/**/*from ww w  .ja va2s.c o m*/
  * Copyright (c) 2009 University of Rochester
  *
  * This program is free software; you can redistribute it and/or modify it under the terms of the MIT/X11 license. The text of the  
  * license can be found at http://www.opensource.org/licenses/mit-license.php and copy of the license can be found on the project
  * website http://www.extensiblecatalog.org/. 
  *
  */

import java.util.HashMap;

import java.util.Map;

public class Main {
    /** Create a string representation of hash map as
     * key="value" key="value" ...
     * @param map
     * @return
     */
    public static String hashMapToString(HashMap<String, ?> map) {
        StringBuffer text = new StringBuffer();
        boolean isFirst = true;
        for (Map.Entry<String, ?> e : map.entrySet()) {
            if (!isFirst)
                text.append(' ');
            text.append(e.getKey()).append("=\"").append(e.getValue().toString()).append('"');
            isFirst = false;
        }
        return text.toString();
    }
}

Related

  1. hashMapToArray(HashMap map)
  2. HashMapToParamsString(HashMap params)
  3. toArrayListHashMapStrObj(Object object)