Java String to Map stringToMap(String[] strings)

Here you can find the source of stringToMap(String[] strings)

Description

Convert an array of String which likes "key=value" to a Map.

License

Apache License

Parameter

Parameter Description
strings a parameter

Declaration

public static Map stringToMap(String[] strings) 

Method Source Code

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

import java.util.HashMap;

import java.util.Map;

public class Main {
    /**/*from  w  w  w  . j  a  v a2  s . com*/
     * Convert an array of String which likes "key=value" to a Map.
     * 
     * @param strings
     * @return
     */
    public static Map stringToMap(String[] strings) {
        Map result = new HashMap();
        for (int i = 0; i < strings.length; i++) {
            int pos = strings[i].indexOf('=');
            if (pos != -1 && pos != 0 && pos != strings[i].length()) {
                String key = strings[i].substring(0, pos);
                String value = strings[i].substring(pos + 1);
                result.put(key, value);
            }
        }

        return result;
    }
}

Related

  1. stringToMap(String src)
  2. stringToMap(String src)
  3. StringToMap(String str)
  4. stringToMap(String str)
  5. stringToMap(String value)
  6. toMap(String componentName, String contextName)
  7. toMap(String jsonStr)
  8. toMap(String parameters)
  9. toMap(String s)