Java examples for Collection Framework:Map
convert Dictionary To Map
/******************************************************************************* * 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:/* w ww . j av a2 s . co m*/ * Composent, Inc. - initial API and implementation ******************************************************************************/ import java.util.Dictionary; import java.util.Enumeration; 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); if (SerializationUtil.isSerializable(value)) result.put(key, value); else result.put(key, String.valueOf(value)); } return result; } }