Here you can find the source of createMap(String[] mappings, String sep)
Parameter | Description |
---|---|
mappings | List of mappings. |
sep | Separator used in each mapping. |
public static Map<String, String> createMap(String[] mappings, String sep)
//package com.java2s; import java.util.HashMap; import java.util.Map; public class Main { /**//from ww w .j a va 2 s. co m * Create map from string description. * * The input mapping describes single mapping in a single string, separated * by the provided separator. * * On input <code>[ "a:alpha", "c:charlie" ]</code> the output would be * <code>{ "a" => "alpha", "c" => "charlie" }</code>. * * @param mappings * List of mappings. * @param sep * Separator used in each mapping. * @return Map corresponding to the provided mapping. */ public static Map<String, String> createMap(String[] mappings, String sep) { Map<String, String> dict = new HashMap<>(); for (String m : mappings) { String[] parts = m.split(sep, 2); if (parts.length == 1) { dict.put(m, m); } else { dict.put(parts[0], parts[1]); } } return dict; } }