Java String to Map toMap(String source)

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

Description

to Map

License

Apache License

Declaration

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

Method Source Code

//package com.java2s;
/* //  w w  w .  j  a  v a2s  . co  m
 * Copyright 2012-2015 Aerospike, Inc.
 *
 * Portions may be licensed to Aerospike, Inc. under one or more contributor
 * license agreements.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

import java.util.HashMap;

import java.util.Map;

public class Main {
    public static Map<String, String> toMap(String source) {
        HashMap<String, String> responses = new HashMap<String, String>();
        String values[] = source.split(";");

        for (String value : values) {
            String nv[] = value.split("=");

            if (nv.length >= 2) {
                responses.put(nv[0], nv[1]);
            } else if (nv.length == 1) {
                responses.put(nv[0], null);
            }
        }

        return responses.size() != 0 ? responses : null;

    }
}

Related

  1. toMap(String componentName, String contextName)
  2. toMap(String jsonStr)
  3. toMap(String parameters)
  4. toMap(String s)
  5. toMap(String s)
  6. toMap(String str)