Convert a map of string arrays to a map of string lists. - Java java.util

Java examples for java.util:List Convert

Description

Convert a map of string arrays to a map of string lists.

Demo Code


//package com.java2s;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class Main {
    /**/*from  w  ww  .j  a va  2 s  . c o m*/
     * Convert a map of string arrays to a map of string lists.
     * 
     * @param parameterMap
     *            The map of string arrays.
     * @return The map of string lists.
     */
    public static Map<String, String[]> toArrays(
            Map<String, List<String>> parameterMap) {
        Map<String, String[]> result = new TreeMap<String, String[]>();
        for (String key : parameterMap.keySet()) {
            List<String> list = parameterMap.get(key);
            String[] array = new String[list.size()];
            list.toArray(array);
            result.put(key, array);
        }
        return result;
    }
}

Related Tutorials