Java String to Map stringToMap(String str)

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

Description

string To Map

License

Apache License

Declaration

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

Method Source Code

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

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

public class Main {
    public static Map<String, String> stringToMap(String str) {
        Map<String, String> res = new HashMap<String, String>();
        int start = 0;
        int index;
        while (start < str.length()) {
            index = str.indexOf(',', start);
            if (index < 0) {
                index = str.length();/*from  www  .  j a v  a2  s.  com*/
            }
            String col = str.substring(start, index).trim();
            start = index + 1;
            if (col.length() > 0) {
                index = col.indexOf(':');
                String name = col;
                String value = "";
                if (index >= 0) {
                    name = col.substring(0, index).trim();
                    value = col.substring(index + 1).trim();
                }
                res.put(name, value);
            }
        }
        return res;
    }
}

Related

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