Here you can find the source of mapToString(final Map
Parameter | Description |
---|---|
m | map to transform |
public static String mapToString(final Map<String, String> m)
//package com.java2s; /* Copyright (c) 2011-2014 Pushing Inertia * All rights reserved. http://pushinginertia.com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License./* w w w.j a v a2 s .com*/ */ import java.util.Map; public class Main { /** * Transforms a map to a string containing name-value pairs separated by '&'. * @param m map to transform * @return resulting string */ public static String mapToString(final Map<String, String> m) { final StringBuilder sb = new StringBuilder(); for (Map.Entry<String, String> e : m.entrySet()) { sb.append(e.getKey().replace("&", "&&")).append('='); final String value = e.getValue(); if (value != null) sb.append(e.getValue().replace("&", "&&")); sb.append('&'); } sb.setLength(sb.length() - 1); return sb.toString(); } }