Java Map to String toStringMap(Map map)

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

Description

Transform a map to a string map.

License

Apache License

Parameter

Parameter Description
map the map with key type and value unknown.

Return

a string map.

Declaration

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

Method Source Code

//package com.java2s;
/*//w  w  w. ja v a  2 s .c om
 * Copyright 2017 MovingBlocks
 *
 * 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.
 */

import java.util.HashMap;
import java.util.Map;

public class Main {
    /**
     * Transform a map to a string map.
     * @param map the map with key type and value unknown.
     * @return a string map.
     */
    public static Map<String, String> toStringMap(Map<?, ?> map) {
        Map<String, String> stringMap = new HashMap<>();
        for (Map.Entry<?, ?> entry : map.entrySet()) {
            stringMap.put(entry.getKey().toString(), entry.getValue()
                    .toString());
        }
        return stringMap;
    }
}

Related

  1. toString(Map map)
  2. toString(Map params)
  3. toString(Map map)
  4. toString(Map map, StringBuilder sb)
  5. toStringMap( Map enumMap)
  6. toStringMap(Map src)
  7. toStringMap(Properties properties)
  8. toStringMap(String... pairs)
  9. toStringMap(String... pairs)