Flatten a map of string arrays to a map of strings using the first item in each array. - Java java.util

Java examples for java.util:Map Operation

Description

Flatten a map of string arrays to a map of strings using the first item in each array.

Demo Code


//package com.java2s;

import java.util.Map;
import java.util.TreeMap;

public class Main {
    /**//from   w w  w  .j  a  v a  2  s  . c  om
     * Flatten a map of string arrays to a map of strings using the first item in each array.
     * 
     * @param parameterMap
     *            The map of string arrays.
     * @return A map of strings.
     */
    public static Map<String, String> flatten(
            Map<String, String[]> parameterMap) {
        Map<String, String> result = new TreeMap<String, String>();
        for (String key : parameterMap.keySet()) {
            result.put(key, parameterMap.get(key)[0]);
        }
        return result;
    }
}

Related Tutorials