package com.itheima.train;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class MapTest {
	public static void main(String[] args) {
		// 创建一个Map集合,
		Map<String, String> star=new HashMap<>();
		//往集合中添加元素
		star.put("黄晓明", "杨颖");
		star.put("李晨", "范冰冰");
		star.put("贾乃亮", "李小璐");
		star.put("罗晋", "唐嫣");
//		method01(star);
		method02(star);
	}
	
	/**
	 * 通过创建键值对对象,遍历键值对来获取集合中的键与值;
	 * @param star
	 */
	private static void method02(Map<String, String> star) {
		//创建一个键值对对象
		Set<Map.Entry<String, String>> entrySet=star.entrySet();
		//创建键值对对象的专属迭代器
		Iterator<Map.Entry<String, String>> it2=entrySet.iterator();
		//使用迭代器遍历集合
		while(it2.hasNext()){
			Map.Entry<String, String> temp=it2.next();
			String key=temp.getKey();
			String value=temp.getValue();
			System.out.println(key+"love"+value);
		}
	}
	
	
	/**
	 * 通过创建键的集合对象来遍历Map集合
	 * @param star
	 */
	private static void method01(Map<String, String> star) {
		//通过创建键的集合来遍历Map集合
		Set<String> keySet=star.keySet();
		//创建键的集合的专属迭代器
		Iterator<String> it1=keySet.iterator();
		//使用迭代器查找元素
		while(it1.hasNext()){
			String temp=it1.next();
			System.out.println(temp+"LOVE"+star.get(temp));
		}
	}
}
最近下载更多
                
                hw272619     LV6
                2019年9月13日
            
            
        
                低调人     LV38
                2019年7月11日
            
            
        
                wxjwhqwy     LV29
                2019年4月13日
            
            
        
                kinggode     LV14
                2018年11月1日
            
            
        
                DawnWalker     LV19
                2018年9月9日
            
            
        
                z924931408     LV25
                2018年8月24日
            
            
        
                海海海     LV2
                2018年7月29日
            
            
        
                海乐神     LV4
                2018年7月25日
            
            
        
                405117548     LV6
                2018年7月10日
            
            
        
                kenpfang     LV18
                2018年5月18日
            
            
        
最近浏览更多
                
                ljt289917726     LV3
                2022年9月7日
            
            
        
                silipxf     LV2
                2021年5月12日
            
            
        
                wlfzuidaima     LV1
                2020年5月8日
            
            
        
                弥尘123456     LV4
                2020年2月19日
            
            
        
                wjm777777     LV1
                2019年12月2日
            
            
        
                luohaipeng     LV23
                2019年11月18日
            
            
        
                hw272619     LV6
                2019年9月13日
            
            
        
                15232583526     LV1
                2019年8月7日
            
            
        
                低调人     LV38
                2019年7月11日
            
            
        
                suagcf     LV9
                2019年5月8日
            
            
        
                
                
                