package com.puhui.decision.service.impl;
import org.apache.commons.collections.map.HashedMap; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; /** * Created by finup on 2018/4/5. */ public class TestMap { public static void main(String[] args) { Map<String,String> map=new HashMap(); map.put("1", "张三"); map.put("2", "李四"); //map.put("3", "王五"); System.out.println("方法一:"); Iterator iterator=map.entrySet().iterator(); while(iterator.hasNext()){ Map.Entry<String, String> entry= (Map.Entry<String, String>) iterator.next(); System.out.println("key:"+entry.getKey()+" value"+entry.getValue()); } Map m = new HashedMap(); String keyAll=null; String valueAll=null; for(Map.Entry<String,String> entry : map.entrySet()) { System.out.println("key:"+entry.getKey()+" value"+entry.getValue()); if("1".equals(entry.getKey())) { keyAll = entry.getValue(); } else valueAll = entry.getValue(); } m.put(keyAll,valueAll); System.out.printf(keyAll+"---"+); for(String item : map.keySet()) { System.out.println("key:"+item+" value"+map.get(item)); if("1".equals(item)) { //m.put(map.get(item),) } } } }