Java String to Map toMap(String s)

Here you can find the source of toMap(String s)

Description

to Map

License

Apache License

Declaration

public static Map<String, String> toMap(String s) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    private static final String K_V_SEPARATOR = "=>";

    public static Map<String, String> toMap(String s) {
        Map<String, String> m = new HashMap<String, String>();
        if (s == null || s.trim().isEmpty()) {
            return m;
        }/*w w w . j av  a2s. com*/
        String[] tokens = s.split(", ");
        for (String token : tokens) {
            String[] kv = token.split(K_V_SEPARATOR);
            String k = kv[0];
            k = k.trim().substring(1, k.length() - 1);
            String v = kv[1];
            v = v.trim().substring(1, v.length() - 1);
            m.put(k, v);
        }
        return m;
    }
}

Related

  1. stringToMap(String[] strings)
  2. toMap(String componentName, String contextName)
  3. toMap(String jsonStr)
  4. toMap(String parameters)
  5. toMap(String s)
  6. toMap(String source)
  7. toMap(String str)