Java Map to String mapToStr(Map map)

Here you can find the source of mapToStr(Map map)

Description

map To Str

License

Mozilla Public License

Declaration

public static String mapToStr(Map<String, ?> map) 

Method Source Code

//package com.java2s;
/******************************************************************************
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0.  If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/.
 * /*from w ww  .  jav  a  2  s .  co  m*/
 * Software distributed under the License is distributed on an "AS IS" basis, 
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for 
 * the specific language governing rights and limitations under the License.
 *
 * The Original Code is: Jsoda
 * The Initial Developer of the Original Code is: William Wong (williamw520@gmail.com)
 * Portions created by William Wong are Copyright (C) 2012 William Wong, All Rights Reserved.
 *
 ******************************************************************************/

import java.util.*;

public class Main {
    public static String mapToStr(Map<String, ?> map) {
        StringBuilder sb = new StringBuilder();
        boolean isFirst = true;

        sb.append("{");

        for (Map.Entry<String, ?> entry : map.entrySet()) {
            if (isFirst)
                isFirst = false;
            else
                sb.append(",");
            String valueStr = "" + entry.getValue();
            sb.append(entry.getKey()).append("=").append(valueStr);
        }

        sb.append("}");
        return sb.toString();
    }
}

Related

  1. mapToStr(java.util.Map hm, char sep1, char sep2)
  2. mapToStr(Map map)
  3. mapToString(final Map m)
  4. mapToString(final Map m)
  5. mapToString(final Map map)