package com.company;
import java.util.*;
/**
* Created by ttc on 16-10-28.
*/
public class MAP
{
public static void main(String[] args)
{
Map<String,String> map = new HashMap<String,String>();
map.put("cat","猫");
map.put("dog","狗");
map.put("bird","鸟");
map.put("pig","猪");
map.put("monkey","猴");
System.out.println("请输入");
Scanner sc =new Scanner(System.in);
String st=sc.nextLine();
if(map.containsKey(st))//包含
{
System.out.println(map.get(st));
}
else
{
System.out.println("Null");
}
// List<String> ls=new ArrayList<String>();
// ls.add("shdjsk");
// ls.add("sdasd");
// for(String strTemp:ls)
// {
// System.out.println(strTemp);
// }
for(Map.Entry<String,String> me : map.entrySet())
{
String str1 =me.getKey();
String str2 =me.getValue();
System.out.println(str1+" "+str2);
}
}
}
map 应用 遍历
最新推荐文章于 2024-05-22 17:05:03 发布