Java Map from Array map(String... args)

Here you can find the source of map(String... args)

Description

map

License

Open Source License

Declaration

public static HashMap<String, Object> map(String... args) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.HashMap;

public class Main {
    public static HashMap<String, Object> map(String... args) {
        return map((Object[]) args);
    }/*from   w w  w. j  a v  a2 s.  c  o m*/

    public static HashMap<String, Object> map(Object... args) {
        if (args.length % 2 == 1)
            new Exception("Odd number of arguments");

        HashMap<String, Object> r = new HashMap<>();
        for (int i = 0; i < args.length; i += 2) {
            r.put((String) args[i], args[i + 1]);
        }

        return r;
    }
}

Related

  1. map(Object... objs)
  2. map(Object... oo)
  3. map(Object... params)
  4. map(String k, Object v)
  5. map(String key, String val)
  6. map(String... args)
  7. map(String... keysAndValues)
  8. map(String... keyValues)
  9. map(String... strings)