集册 Java实例教程 将字典转换为映射

将字典转换为映射

欢马劈雪     最近更新时间:2020-01-02 10:19:05

901
将字典转换为映射

/*******************************************************************************

 * Copyright (c) 2015 Composent, Inc. and others. All rights reserved. This

 * program and the accompanying materials are made available under the terms of

 * the Eclipse Public License v1.0 which accompanies this distribution, and is

 * available at http://www.eclipse.org/legal/epl-v10.html

 *

 * Contributors:

 *   Composent, Inc. - initial API and implementation

 ******************************************************************************/

import java.util.Dictionary;

import java.util.Enumeration;// from 时代Java - N o w  J a v a . c o m

import java.util.HashMap;

import java.util.Iterator;

import java.util.Map;

import java.util.TreeMap;


public class Main{

    @SuppressWarnings({ "rawtypes", "unchecked" })

    public static Map convertDictionaryToMap(Dictionary dict) {

        Map result = new HashMap();

        for (Enumeration e = dict.keys(); e.hasMoreElements();) {

            String key = (String) e.nextElement();

            Object value = dict.get(key);

            
展开阅读全文