HashMap全部方法的摘要

//HashMap全部方法的摘要

public class TestMap7 {
 public static void main(String[] args){
  Map<String,Integer> map=new HashMap<String,Integer>();
  
  map.put("e", 8);
  map.put("b", 67);
  map.put("d", 23);
  map.put("a", 67);
  
//1、 map.entrySet();方法的用法
//  Iterator ite=map.entrySet().iterator();
//  while(ite.hasNext()){
//  Map.Entry<String, Integer> entry=(Map.Entry<String, Integer>)ite.next();
//      System.out.print(entry.getKey()+"/");
//      System.out.println(entry.getValue());
//  }
  
  
//2、  map.clear()与map.isEmpty();的用法
//      System.out.println(map.isEmpty());//答案:false
//      map.clear();//清空map
//      System.out.println(map.isEmpty());//答案:true
     
  
//3、  map.containsKey();map.containsValue();判断key或value是否存在
//      System.out.println(map.containsKey("a"));//true
//      System.out.println(map.containsValue(23));//true

  
//   map.get();的用法 
//      System.out.println(map.get("a"));
//      map中要是没有这个key,那value就的值为空
//         System.out.println(map.get("v"));
  
  
//      map.keySet();只取map中key的值。
//      Iterator ite=map.keySet().iterator();
//      while(ite.hasNext()){
//       String srings=(String)ite.next();
//       System.out.println(srings);
//      }
  
  
//    map.remove();的用法
//    System.out.println(map.remove("a")+"-------------");
//   Iterator ite=map.entrySet().iterator();
//   while(ite.hasNext()){
//   Map.Entry<String, Integer> entry=(Map.Entry<String, Integer>)ite.next();
//       System.out.print(entry.getKey()+"/");
//       System.out.println(entry.getValue());
//   }
  
  
//    map.size();返回map映射的大小。
//      System.out.println(map.size());
  
  
//    map.values(); 取出map中values;
//    Iterator ite=map.values().iterator();
//          while(ite.hasNext()){
//             Integer integ=(Integer)ite.next();
//             System.out.println(integ);
//        }
     
  
 }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值