public class BankTest01 {
public static void main(String[] args) {
Map map = new HashMap();
String [ ] a={"1","2","3","4"};
String [ ] b={"a","b","c","d"};
for (int i=0;i<a.length;i++){
//map集合添加数据
map.put(a[i],b[i]);
}
// 遍历map集合,输出map
for (Object string : map.keySet()){
System.out.println("key:"+string+",value:"+map.get(string));
}
String key = "4";
//判断是否包含指定的键值
boolean contains = map.containsKey(key);
//如果条件为真
if (contains) {
System.out.println("在Map集合中包含键名" + key+",它的值是:"+map.get(key)); //输出信息
} else {
System.out.println("在Map集合中不包含键名" + key);
}
}
java中把两个数组转换成map,并判断是否包含某个值
最新推荐文章于 2024-06-29 03:10:17 发布