zoukankan      html  css  js  c++  java
  • hashmap的使用

    package tcc.test.collection;

    import java.util.HashMap;
    import java.util.Map;

    /**
    * @author tcc:
    * @version 创建时间:2020年12月8日 下午7:39:28
    * 类说明
    */
    public class HashMapTest {

    public static void main(String[] args) {
    // 声明HashMap对象
    Map<String,Integer> map= new HashMap<>();

    //添加数据
    map.put("ZhangYi",98);
    map.put("WangEr",99);
    map.put("ZhangShan",89);
    map.put("Lisi",92);

    //根据键值对键值获取数据‘’
    int value=map.get("Lisi");
    System.out.println("kay:Lisi And value:"+value);

    //获取Map中键值对的个数
    int size=map.size();
    System.out.println("map 中的键值对个数为:"+size);

    //判断Map集合中是否包含键为key的键值对
    boolean b1=map.containsKey("LiSI");
    boolean b2=map.containsKey("Lisi");
    System.out.println("是否包含键值为LiSI的键值对数据:"+b1);
    System.out.println("是否包含键值为Lisi的键值对数据:"+b2);

    //判断Map集合中是否包含值为value的键值对
    boolean b3=map.containsValue(99);
    boolean b4=map.containsValue(100);
    System.out.println("是否包含值为99的键值对数据:"+b3);
    System.out.println("是否包含值为100的键值对数据:"+b4);

    //判断Map集合中是否没有任何键值对

    boolean b5=map.isEmpty();
    System.out.println("map中键值对数据是否为空:"+b5);

    //根据键值删除Map中键值对
    int value2=map.remove("Lisi");
    System.out.println("删除了键为Lisi的键值对数据,其值为:"+value2);

    boolean b6=map.containsKey("Lisi");
    System.out.println("是否包含键值为Lisi的键值对数据:"+b6);

    //清空Map集合中所有的键值对
    map.clear();
    boolean b7=map.isEmpty();
    System.out.println("map中键值对数据是否为空:"+b7);

    }

    }

  • 相关阅读:
    football statistics
    频繁模式挖掘 Apriori算法 FP-tree
    回首页---用通用底部栏,不用回退键,且多次点击,刷新首页
    对剪切板的失控异常的处理---多半的时间再处理剪切板的失控---冗余操作
    登陆
    搜狗输入法APP的2个剪切板内容获取入口
    实现对屏幕指定内容的操作
    定时删除clientmqueue
    局部优化与整体效果 新增时间>节省时间 权衡利弊
    实时系统的目标
  • 原文地址:https://www.cnblogs.com/tongcc/p/14105247.html
Copyright © 2011-2022 走看看