Java Map to String toStringMap(String... pairs)

Here you can find the source of toStringMap(String... pairs)

Description

to String Map

License

Apache License

Declaration

public static Map<String, String> toStringMap(String... pairs) 

Method Source Code

//package com.java2s;
/*//from  www. j a v a2  s.  co  m
 *  
 * 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.Map;

public class Main {
    public static Map<String, String> toStringMap(String... pairs) {
        Map<String, String> parameters = new java.util.HashMap<String, String>();
        if (pairs.length > 0) {
            if (pairs.length % 2 != 0) {
                throw new IllegalArgumentException("pairs must be even.");
            }
            for (int i = 0; i < pairs.length; i = i + 2) {
                parameters.put(pairs[i], pairs[i + 1]);
            }
        }
        return parameters;
    }
}

Related

  1. toString(Map map, StringBuilder sb)
  2. toStringMap( Map enumMap)
  3. toStringMap(Map map)
  4. toStringMap(Map src)
  5. toStringMap(Properties properties)
  6. toStringMap(String... pairs)