Java Map Add arrayToMap(int[] array)

Here you can find the source of arrayToMap(int[] array)

Description

array To Map

License

Apache License

Declaration

public static Map<Integer, Integer> arrayToMap(int[] array) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.HashMap;

import java.util.Map;

public class Main {
    public static Map<Integer, Integer> arrayToMap(int[] array) {
        Map<Integer, Integer> ret = new HashMap<Integer, Integer>();
        for (int i = 0; i < array.length; i++)
            ret.put(i + 1, array[i]);/*from  w  w w. ja va2s  .  co  m*/
        return ret;
    }

    public static <T> Map<Integer, T> arrayToMap(T[] array) {
        Map<Integer, T> ret = new HashMap<Integer, T>();
        for (int i = 0; i < array.length; i++)
            ret.put(i + 1, array[i]);
        return ret;
    }
}

Related

  1. addToMapListUnique(Map> mapList, T key, List values)
  2. addToMapMap(Map> map, K1 key1, K2 key2, V value)
  3. addToMapMap(Map> map, T key, V val)
  4. addToMapOfLists(Map> map, S key, T value)
  5. arrayAsMap(Object... t)
  6. arrayToMap(Map destMap, Object[]... oaaArray)
  7. ArrayToMap(Object[] a)
  8. arrayToMap(Object[] array)
  9. arrayToMap(Object[] array, Object value)