Java Map Create createMap(Object... args)

Here you can find the source of createMap(Object... args)

Description

Helper function to create maps easier.

License

Open Source License

Parameter

Parameter Description
args map entries, pass key/value pairs

Return

map

Declaration

private static Map<Object, Object> createMap(Object... args) 

Method Source Code


//package com.java2s;
/*/*from   w  w w  . j a  v a 2  s . co m*/
 * RED5 Open Source Flash Server - http://www.osflash.org/red5
 *
 * Copyright (c) 2006-2007 by respective authors (see below). All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License as published by the Free Software
 * Foundation; either version 2.1 of the License, or (at your option) any later
 * version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along
 * with this library; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

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

public class Main {
    /**
     * Helper function to create maps easier.
     * 
     * @param args map entries, pass key/value pairs
     * @return map
     */
    private static Map<Object, Object> createMap(Object... args) {
        assert args.length % 2 == 0;
        Map<Object, Object> result = new HashMap<Object, Object>();
        for (int i = 0; i < args.length; i += 2) {
            result.put(args[i], args[i + 1]);
        }
        return result;
    }
}

Related

  1. createMap(K[] keys, V[] values)
  2. createMap(List keys, List values)
  3. createMap(List keys, List values)
  4. createMap(Map map)
  5. createMap(Object keys[], Object values[])
  6. createMap(Object... objects)
  7. createMap(Object... objects)
  8. createMap(Object[] keysValues)
  9. createMap(String entries)

  10. HOME | Copyright © www.java2s.com 2016