package day18_map;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class MapDemo {
public static void main(String[] args) {
Map<String,String> map = new HashMap<String,String>();
map.put("1", "赵云");
map.put("2", "张飞");
map.put("3", "李四");
//通过KeySet获取ket的set集合
Set<String> set = map.keySet();
for(String str: set){
System.out.println(str+"***"+map.get(str));
}
//通过values()获取值返回collection集合
Collection<String> c = map.values();
for(String str: c){
System.out.println(str);
}
//通过entrySet()方法获取键值对
Set<Map.Entry<String,String>> set1 = map.entrySet();
for(Map.Entry<String, String> me : map.entrySet()){
String key = me.getKey();
String value = me.getValue();
System.out.println(key+"***"+value);
}
}
}
|
|