Java Array to Map toMap(String[] keys)

Here you can find the source of toMap(String[] keys)

Description

Convert array of strings to string→index map.

License

Open Source License

Declaration

public static Map<String, Integer> toMap(String[] keys) 

Method Source Code

//package com.java2s;
/*//from www  .  ja v a  2  s  .  c o m
 * Copyright (c) 2012 The ANTLR Project. All rights reserved.
 * Use of this file is governed by the BSD-3-Clause license that
 * can be found in the LICENSE.txt file in the project root.
 */

import java.util.HashMap;

import java.util.Map;

public class Main {
    /** Convert array of strings to string&rarr;index map. Useful for
     *  converting rulenames to name&rarr;ruleindex map.
     */
    public static Map<String, Integer> toMap(String[] keys) {
        Map<String, Integer> m = new HashMap<String, Integer>();
        for (int i = 0; i < keys.length; i++) {
            m.put(keys[i], i);
        }
        return m;
    }
}

Related

  1. toMap(K[] keys, V[] values)
  2. toMap(K[] keys, V[] values)
  3. toMap(String... args)
  4. toMap(String... keysAndValues)
  5. toMap(String[] keyNames, T[] values)
  6. toMap(String[]... wordMappings)
  7. toMap(String[][] checksumsArray)
  8. toMap(String[][] strings)
  9. toMap(T[][] pairs)