Java String to Map stringToMap(String src)

Here you can find the source of stringToMap(String src)

Description

Convert a string of key/val pairs to a map.

License

Creative Commons License

Parameter

Parameter Description
src the original string

Return

the map

Declaration

public static Map<String, String> stringToMap(String src) 

Method Source Code


//package com.java2s;

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

public class Main {
    /**//  w  w w  .j  av a  2  s .c  om
     * Convert a string of key/val pairs to a map.
     *
     * @param src the original string
     * @return the map
     */
    public static Map<String, String> stringToMap(String src) {
        Map<String, String> ret = new HashMap<String, String>();
        String[] params = src.split(";");
        for (String param : params) {
            int ei = param.indexOf("=");
            if (ei == -1) {
                continue;
            }
            String key = param.substring(0, ei).trim();
            String val = param.substring(ei + 1);
            ret.put(key, val);
        }
        return ret;
    }
}

Related

  1. stringToMap(final String s)
  2. stringToMap(final String s)
  3. stringToMap(String append)
  4. stringToMap(String source, String delimiter)
  5. stringToMap(String src)
  6. StringToMap(String str)
  7. stringToMap(String str)
  8. stringToMap(String value)
  9. stringToMap(String[] strings)