Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Creative Commons License 

import java.util.Map;

public class Main {
    /**
     * Converts a map into a delimited string value.
     * A "{@literal =}" separates the keys and values and a "{@literal &}" separates the key pairs.
     * @param stringMap map to convert
     * @return string representation of map
     */
    public static String convertMapToString(final Map<String, String> stringMap) {
        final StringBuilder sb = new StringBuilder();
        final char keySeparator = '=';
        final char pairSeparator = '&';
        for (final Map.Entry<String, String> pair : stringMap.entrySet()) {
            sb.append(pair.getKey());
            sb.append(keySeparator);
            sb.append(pair.getValue());
            sb.append(pairSeparator);
        }
        return sb.toString().substring(0, sb.length() - 1);
    }
}