Here you can find the source of mapToString(Map map)
Parameter | Description |
---|---|
map | Input map |
public static String mapToString(Map map)
//package com.java2s; /******************************************************************************* * Copyright (c) 2016 Pablo Pavon-Marino. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v2.1 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/lgpl.html * * Contributors:// ww w . j a v a 2 s .c om * Pablo Pavon-Marino - Jose-Luis Izquierdo-Zaragoza, up to version 0.3.1 * Pablo Pavon-Marino - from version 0.4.0 onwards ******************************************************************************/ import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; public class Main { /** * Outputs entries from a {@code Map} to a {@code String}. Default * separator between each key and value is '=', and separator between key-value pair * is ', '. * * @param map Input map * @return {@code String} representing the map * */ public static String mapToString(Map map) { return mapToString(map, "=", ", "); } /** * Outputs entries from a {@code Map} to a {@code String}. * * @param map Input map * @param keyValueSeparator Separator between keys and values * @param entrySeparator Separator between key-value pairs * @return {@code String} representing the map * */ public static String mapToString(Map map, String keyValueSeparator, String entrySeparator) { StringBuilder string = new StringBuilder(); Iterator it = map.entrySet().iterator(); while (it.hasNext()) { Entry entry = (Entry) it.next(); if (string.length() > 0) string.append(entrySeparator); string.append(entry.getKey()); string.append(keyValueSeparator); string.append(entry.getValue()); } return string.toString(); } }