Here you can find the source of createMap(T... _args)
Parameter | Description |
---|---|
T | map type |
_args | parameter array, any type |
@SafeVarargs public static <T> Map<T, T> createMap(T... _args)
//package com.java2s; //License from project: Open Source License import java.util.Arrays; import java.util.HashMap; import java.util.Map; public class Main { /**/* w ww . ja v a 2 s.co m*/ * Creates a map from the even-sized parameter array. * @param <T> map type * @param _args parameter array, any type * @return map of parameter type */ @SafeVarargs public static <T> Map<T, T> createMap(T... _args) { Map<T, T> map = new HashMap<>(); if (_args != null) { if (_args.length % 2 != 0) { throw new IllegalArgumentException( "Even number of parameters required to create map: " + Arrays.toString(_args)); } for (int i = 0; i < _args.length;) { map.put(_args[i], _args[i + 1]); i += 2; } } return map; } }