public class MapUrl {
public static String Check(String key)
{
String url;
//创建key和value都是string类型的字典
Map<String,String> dict = new HashMap<>();
//存值
dict.put("CALL0001","http://localhost:8080/call");
dict.put("STOP0002","http://localhost:8080/stop");
//首先判要查询的key是否存在
if(dict.containsKey(key))
{
//存在的话,取value值
url = dict.get(key);
}
else
{
url="the url is not exist";
}
return url;
}
public static void main(String[] args) {
String geturl = Check("CALL0001"); //字典取url
}
}