Java Array to Map arrayToMap(int[] array)

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

Description

array To Map

License

Open Source License

Declaration

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

Method Source Code

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

import java.util.*;

public class Main {
    public static HashMap<Integer, Integer> arrayToMap(int[] array) {
        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
        for (int i = 0; i < array.length; i++) {
            map.put(i + 1, array[i]);/*www .j a  v a 2s.c om*/
        }
        return map;
    }

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

Related

  1. toMap(K[] keys, V[] values)
  2. toMap(K[] keys, V[] values)
  3. toMap(String... args)
  4. toMap(String... keysAndValues)