zoukankan      html  css  js  c++  java
  • java——基础数据类型——map集合操作

    import java.util.*;

    public class map

    {

        public static void main( String[] args )

        {

            //Map list = new HashMap();

            Map<Integer, String> map = new HashMap<>();

            map.put(1,"shen");

            map.put(2,"wei");

            System.out.println(map.size());

            System.out.println("==================================1");

            System.out.println(map);

            System.out.println("==================================2");

            System.out.println(map.get(1));

            System.out.println(map.get(2));

            System.out.println("==================================3");

            Boolean a = map.containsKey(1);  //此映射是否包含

            System.out.println(a);

            System.out.println("==================================4");

            Boolean b = map.containsKey(3);

            System.out.println(b);

            System.out.println("==================================5");

            map.remove(2);

            System.out.println(map.size());

            System.out.println(map);

            System.out.println("==================================6");

            Object  value = map.get(1);

            System.out.println(value);

            System.out.println("==================================7");

            Boolean c = map.containsValue("shen");   //是否包含指定值

            System.out.println(c);

            System.out.println("==================================8");

            Boolean d = map.isEmpty();            //判断是否为空

            System.out.println(d);

            System.out.println("==================================9");

            map.put(2,"wei");

            map.put(3,"wei");

            Set<Integer> key = map.keySet();   //获取map中所有的key值,

            System.out.println(key);

            System.out.println("==================================9______1");

            Collection<String> value4 = map.values();   //获取map中所有的value值,

            System.out.println(value4);

            System.out.println("==================================9______2");

            map.clear();      //清空

            Boolean e = map.isEmpty();

            System.out.println(e);

            System.out.println("==================================10");

        }

    }

    ==============================================================================================================================================================

    执行结果:

    2

    ==================================1

    {1=shen, 2=wei}

    ==================================2

    shen

    wei

    ==================================3

    true

    ==================================4

    false

    ==================================5

    1

    {1=shen}

    ==================================6

    shen

    ==================================7

    true

    ==================================8

    false

    ==================================9

    [1, 2, 3]

    ==================================9______1

    [shen, wei, wei]

    ==================================9______2

    true

    ==================================10

  • 相关阅读:
    Resource interpreted as Stylesheet but transferred with MIME type application/x-css
    scrapy 的settings.py中设置自定义属性
    scrapy下载图片到指定路径
    scrapy 自动下载图片
    Python处理json的错误 obj, end = self.scan_once(s, idx) ValueError: Expecting property name: line 2 column 17 (char 18)
    [ZJOI2012]数列 题解 [高精]
    [ZJOI2020]传统艺能 题解 [DP+矩阵+分类讨论]
    《终将成为你》简评
    GJGHFD的关键点 题解 [倍增+线段树+贪心]
    GJGHFD的排列 题解 [DP]
  • 原文地址:https://www.cnblogs.com/xiaobaibailongma/p/14426805.html
Copyright © 2011-2022 走看看